Skip to content

Commit

Permalink
Merge pull request #76 from martinvenus/master
Browse files Browse the repository at this point in the history
Fix compatibility with PHP 7.2
  • Loading branch information
enumag authored Dec 4, 2017
2 parents 1319f9d + c0f29bb commit 7ac96ed
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 85 deletions.
27 changes: 6 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ cache:
- $HOME/.composer/cache

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

services:
- redis-server
Expand All @@ -19,26 +18,14 @@ env:
matrix:
- NETTE=nette-2.4-dev
- NETTE=nette-2.4
- NETTE=nette-2.3

matrix:
include:
- php: 5.6
env: NETTE=nette-2.3 COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
- php: 7.0
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
exclude:
- php: 5.4
env: NETTE=nette-2.4-dev
- php: 5.4
env: NETTE=nette-2.4
- php: 5.5
env: NETTE=nette-2.4-dev
- php: 5.5
env: NETTE=nette-2.4
- php: 7.2
env: NETTE=nette-2.4 COVERAGE="-d memory_limit=4096M --coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
allow_failures:
- php: 7.0
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.2
env: NETTE=nette-2.4 COVERAGE="-d memory_limit=4096M --coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"

before_install:
- travis_retry composer self-update
Expand All @@ -53,15 +40,13 @@ addons:
install:
- travis_retry composer update --no-interaction --prefer-dist $COMPOSER_EXTRA_ARGS
- travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint
- travis_retry composer create-project --no-interaction kdyby/code-checker /tmp/code-checker
- travis_retry wget -O /tmp/coveralls.phar https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- tests/travis.phpredis.sh
- redis-cli info |grep version

script:
- vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/
- php /tmp/php-parallel-lint/parallel-lint.php -e php,phpt --exclude vendor .
- php /tmp/code-checker/src/code-checker.php --short-arrays

after_script:
- if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Kdyby/Redis
Requirements
------------

Kdyby/Redis requires PHP 5.4 or higher.
Kdyby/Redis requires PHP 7.0 or higher.

- [Nette Framework](https://github.com/nette/nette)
- [Redis database](http://redis.io)
Expand Down
54 changes: 27 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@
"issues": "https://github.com/kdyby/redis/issues"
},
"require": {
"php": ">=5.4",
"nette/di": "~2.3@dev",
"nette/caching": "~2.3@dev",
"nette/http": "~2.3@dev",
"nette/utils": "~2.3@dev"
"php": ">=7.0",
"nette/di": "~2.4",
"nette/caching": "~2.5",
"nette/http": "~2.4",
"nette/utils": "~2.4"
},
"suggest": {
"ext-redis": "The php redis extension https://github.com/nicolasff/phpredis/ is required for connecting to redis server"
},
"require-dev": {
"nette/application": "~2.3@dev",
"nette/bootstrap": "~2.3@dev",
"nette/caching": "~2.3@dev",
"nette/component-model": "~2.2@dev",
"nette/database": "~2.3@dev",
"nette/deprecated": "~2.2@dev",
"nette/di": "~2.3@dev",
"nette/finder": "~2.3@dev",
"nette/forms": "~2.3@dev",
"nette/http": "~2.3@dev",
"nette/mail": "~2.3@dev",
"nette/neon": "~2.3@dev",
"nette/php-generator": "~2.3@dev",
"nette/reflection": "~2.3@dev",
"nette/robot-loader": "~2.3@dev",
"nette/safe-stream": "~2.3@dev",
"nette/security": "~2.3@dev",
"nette/tokenizer": "~2.2@dev",
"nette/utils": "~2.3@dev",
"latte/latte": "~2.3@dev",
"tracy/tracy": "~2.3@dev",
"nette/application": "~2.4",
"nette/bootstrap": "~2.4",
"nette/caching": "~2.5",
"nette/component-model": "~2.3",
"nette/database": "~2.4",
"nette/deprecated": "~2.4",
"nette/di": "~2.4",
"nette/finder": "~2.4",
"nette/forms": "~2.4",
"nette/http": "~2.4",
"nette/mail": "~2.4",
"nette/neon": "~2.4",
"nette/php-generator": "~2.6",
"nette/reflection": "~2.4",
"nette/robot-loader": "~2.4",
"nette/safe-stream": "~2.3",
"nette/security": "~2.4",
"nette/tokenizer": "~2.3",
"nette/utils": "~2.4",
"latte/latte": "~2.4",
"tracy/tracy": "~2.4",

"nette/tester": "~1.7"
},
Expand All @@ -64,7 +64,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.3-dev"
"dev-master": "4.0-dev"
}
}
}
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/Diagnostics/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
/**
* @author Filip Procházka <[email protected]>
*/
class Panel extends Nette\Object implements IBarPanel
class Panel implements IBarPanel
{
use Nette\SmartObject;

/** @internal */
const TIMER_NAME = 'redis-client-timer';
Expand Down
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/ExclusiveLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
* @author Ondřej Nešpor
* @author Filip Procházka <[email protected]>
*/
class ExclusiveLock extends Nette\Object
class ExclusiveLock
{
use Nette\SmartObject;

/**
* @var RedisClient
Expand Down
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@
*
* @author Filip Procházka <[email protected]>
*/
class RedisClient extends Nette\Object implements \ArrayAccess
class RedisClient implements \ArrayAccess
{
use Nette\SmartObject;

/** @deprecated */
const WITH_SCORES = 'WITHSCORES';
Expand Down
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/RedisJournal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
*
* @author Filip Procházka <[email protected]>
*/
class RedisJournal extends Nette\Object implements Nette\Caching\Storages\IJournal
class RedisJournal implements Nette\Caching\Storages\IJournal
{
use Nette\SmartObject;

/** @internal cache structure */
const NS_NETTE = 'Nette.Journal';
Expand Down
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/RedisSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
*
* @author Filip Procházka <[email protected]>
*/
class RedisSessionHandler extends Nette\Object implements \SessionHandlerInterface
class RedisSessionHandler implements \SessionHandlerInterface
{
use Nette\SmartObject;

/** @internal cache structure */
const NS_NETTE = 'Nette.Session:';
Expand Down
3 changes: 2 additions & 1 deletion src/Kdyby/Redis/RedisStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
*
* @author Filip Procházka <[email protected]>
*/
class RedisStorage extends Nette\Object implements IMultiReadStorage
class RedisStorage implements IMultiReadStorage
{
use Nette\SmartObject;

/** @internal cache structure */
const NS_NETTE = 'Nette.Storage';
Expand Down
9 changes: 6 additions & 3 deletions tests/KdybyTests/Redis/AbstractRedisTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ public function end()
/**
* @author Filip Procházka <[email protected]>
*/
class ClosureExtractor extends Nette\Object
class ClosureExtractor
{
use Nette\SmartObject;

/**
* @var GlobalFunction
Expand Down Expand Up @@ -263,8 +264,9 @@ public function buildScript(\ReflectionClass $class, $repeat)
/**
* @author Filip Procházka <[email protected]>
*/
class NamespaceUses extends Nette\Object
class NamespaceUses
{
use Nette\SmartObject;

/**
* @var \ReflectionClass
Expand Down Expand Up @@ -395,8 +397,9 @@ private function parseFile()
/**
* @author Filip Procházka <[email protected]>
*/
class FunctionCode extends Nette\Object
class FunctionCode
{
use Nette\SmartObject;

/**
* @var \ReflectionFunctionAbstract
Expand Down
8 changes: 2 additions & 6 deletions tests/KdybyTests/Redis/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ExtensionTest extends Tester\TestCase
Assert::true($dic->getService('redis.cacheStorage') instanceof Kdyby\Redis\RedisStorage);
Assert::true($dic->getService('cacheStorage') instanceof Kdyby\Redis\RedisStorage);
Assert::same([
'saveHandler' => 'redis',
'savePath' => 'tcp://127.0.0.1:6379?weight=1&timeout=10&database=0&prefix=Nette.Session%3A',
'save_handler' => 'redis',
'save_path' => 'tcp://127.0.0.1:6379?weight=1&timeout=10&database=0&prefix=Nette.Session%3A',
'referer_check' => '',
'use_cookies' => 1,
'use_only_cookies' => 1,
Expand All @@ -61,10 +61,6 @@ class ExtensionTest extends Tester\TestCase
'cookie_secure' => FALSE,
'cookie_httponly' => TRUE,
'gc_maxlifetime' => 10800,
'cache_limiter' => NULL,
'cache_expire' => NULL,
'hash_function' => NULL,
'hash_bits_per_character' => NULL,
], $dic->getService('session')->getOptions());
}

Expand Down
27 changes: 13 additions & 14 deletions tests/KdybyTests/Redis/RedisSessionHandler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class SessionHandlerTest extends AbstractRedisTestCase
public function testIntegration_existingSession()
{
$sessionId = md5(1);
$session = self::createSession([session_name() => $sessionId, 'nette-browser' => $B = '1lm7e5iqsk']);
$session = self::createSession([session_name() => $sessionId]);

$session->setHandler($handler = new SessionHandlerDecorator(new RedisSessionHandler($this->client)));
$this->client->setupLockDuration(60, 20);

// fake session
$this->client->set('Nette.Session:' . $sessionId, '__NF|' . serialize(['Time' => $T = time() - 1000, 'B' => $B]));
$this->client->set('Nette.Session:' . $sessionId, '__NF|' . serialize(['Time' => $T = time() - 1000]));

$counter = $session->getSection('counter');
$counter->visits += 1;
Expand All @@ -110,12 +110,12 @@ class SessionHandlerTest extends AbstractRedisTestCase
Assert::same(['open', '', 'PHPSESSID'], $handler->series[0][0]);
Assert::same(['read', $sessionId], $handler->series[0][1]);
Assert::same('write', $handler->series[0][2][0]);
Assert::match('__NF|a:3:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:1;}}}', $handler->series[0][2][2]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:1;}}}', $handler->series[0][2][2]);

Assert::same(['open', '', 'PHPSESSID'], $handler->series[1][0]);
Assert::same(['read', $sessionId], $handler->series[1][1]);
Assert::same('write', $handler->series[1][2][0]);
Assert::match('__NF|a:3:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:2;}}}', $handler->series[1][2][2]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:2;}}}', $handler->series[1][2][2]);

Assert::count(1, $this->client->keys('Nette.Session:*'));
}
Expand Down Expand Up @@ -151,15 +151,15 @@ class SessionHandlerTest extends AbstractRedisTestCase
Assert::same('read', $handler1->series[1][1][0]);
Assert::match('%S%', $regeneratedId = $handler1->series[1][1][1]);
Assert::same('write', $handler1->series[1][2][0]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";}', $handler1->series[1][2][2]);
Assert::match('__NF|a:1:{s:4:"Time";i:%S%;}', $handler1->series[1][2][2]);

// close session
Assert::same('write', $handler1->series[2][2][0]);
Assert::match('__NF|a:3:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:1;}}}', $handler1->series[2][2][2]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:1;}}}', $handler1->series[2][2][2]);

Assert::notSame($sessionId, $regeneratedId);

$session2 = self::createSession([session_name() => $regeneratedId, 'nette-browser' => $_SESSION['__NF']['B']]); // no browser, empty session
$session2 = self::createSession([session_name() => $regeneratedId]); // no browser, empty session
$session2->setHandler($handler2 = new SessionHandlerDecorator(new RedisSessionHandler($client = new RedisClient())));
$client->setupLockDuration(60, 20);

Expand All @@ -173,7 +173,7 @@ class SessionHandlerTest extends AbstractRedisTestCase
Assert::same(['open', '', 'PHPSESSID'], $handler2->series[0][0]);
Assert::same(['read', $regeneratedId], $handler2->series[0][1]);
Assert::same('write', $handler2->series[0][2][0]);
Assert::match('__NF|a:3:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:2;}}}', $handler2->series[0][2][2]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:2;}}}', $handler2->series[0][2][2]);

Assert::count(1, $this->client->keys('Nette.Session:*'));
}
Expand Down Expand Up @@ -216,11 +216,11 @@ class SessionHandlerTest extends AbstractRedisTestCase
{
$sessionId = md5(1);

$session = self::createSession([session_name() => $sessionId, 'nette-browser' => $B = '1lm7e5iqsk']);
$session = self::createSession([session_name() => $sessionId]);
$session->setHandler($handler = new SessionHandlerDecorator(new RedisSessionHandler($client = new RedisClient())));

// fake session
$client->set('Nette.Session:' . $sessionId, '__NF|' . serialize(['Time' => $T = time() - 1000, 'B' => $B]));
$client->set('Nette.Session:' . $sessionId, '__NF|' . serialize(['Time' => $T = time() - 1000]));

// open session
$counter = $session->getSection('counter');
Expand All @@ -232,19 +232,18 @@ class SessionHandlerTest extends AbstractRedisTestCase
Assert::same(['open', '', 'PHPSESSID'], $handler->series[0][0]);
Assert::same(['read', $sessionId], $handler->series[0][1]);
Assert::same('write', $handler->series[0][2][0]);
Assert::match('__NF|a:3:{s:4:"Time";i:%S%;s:1:"B";s:10:"%S%";s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:0;}}}', $handler->series[0][2][2]);
Assert::match('__NF|a:2:{s:4:"Time";i:%S%;s:4:"DATA";a:1:{s:7:"counter";a:1:{s:6:"visits";i:0;}}}', $handler->series[0][2][2]);

// only testing the behaviour of high concurency for one request, without regenerating the session id
// 30 processes will be started, but every one of them will work for at least 1 second
// a fuckload (~66%) of the processes should actually fail, because the timeout for lock acquire is 10 sec
$result = $this->threadStress(function () use ($sessionId, $B) {
$result = $this->threadStress(function () use ($sessionId) {
$_COOKIE[session_name()] = $sessionId;
$_COOKIE['nette-browser'] = $B;

$session = new Nette\Http\Session(
new Nette\Http\Request(
new Nette\Http\UrlScript('http://www.kdyby.org'),
NULL, [], [], [session_name() => $sessionId, 'nette-browser' => $B], [], 'GET'
NULL, [], [], [session_name() => $sessionId], [], 'GET'
),
new Nette\Http\Response()
);
Expand Down
8 changes: 1 addition & 7 deletions tests/travis.phpredis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

mkdir /tmp/build-phpredis && cd /tmp/build-phpredis || exit 1

if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then
PHP_REDIS_BRANCH="php7"
else
PHP_REDIS_BRANCH="master"
fi

wget -O phpredis.zip "https://github.com/phpredis/phpredis/archive/$PHP_REDIS_BRANCH.zip" && unzip phpredis.zip && cd phpredis-*/ || exit 1
wget -O phpredis.zip "https://github.com/phpredis/phpredis/archive/master.zip" && unzip phpredis.zip && cd phpredis-*/ || exit 1
echo

phpize && ./configure && make && make install || exit 1
Expand Down

0 comments on commit 7ac96ed

Please sign in to comment.