From 527987d135569f883ba7844f3b9c6317c0bf7b95 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 19 Dec 2018 13:17:51 +0100 Subject: [PATCH 1/5] Test on PHP 7.3 on Travis --- .travis.yml | 54 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9b6bf0..04a8ccb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,24 +14,9 @@ matrix: - php: 7.2 env: - dropPlatform=false - - php: 7.3snapshot + - php: 7.3 env: - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 - - php: 7.3.0RC1 - env: - - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 - php: nightly env: - dropPlatform=false @@ -43,26 +28,11 @@ matrix: env: - dependencies=lowest - dropPlatform=false - - php: 7.3snapshot - env: - - dependencies=lowest - - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 - - php: 7.3.0RC1 + - php: 7.3 env: - dependencies=lowest - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 + - php: nightly env: - dependencies=lowest @@ -75,26 +45,10 @@ matrix: env: - dependencies=highest - dropPlatform=false - - php: 7.3snapshot - env: - - dependencies=highest - - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 - - php: 7.3.0RC1 + - php: 7.3 env: - dependencies=highest - dropPlatform=false - dist: xenial - sudo: required - addons: - apt: - packages: - - libzip4 - php: nightly env: - dependencies=highest From 94206579bcf85252834f05450b0347b5298e4f84 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 19 Dec 2018 14:04:52 +0100 Subject: [PATCH 2/5] test DI file --- composer.json | 3 +- composer.lock | 311 ++++++++++++++++++++++++++++++++++++++++++++++- tests/DiTest.php | 35 ++++++ 3 files changed, 347 insertions(+), 2 deletions(-) create mode 100644 tests/DiTest.php diff --git a/composer.json b/composer.json index f9d1c8b..240eee8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "wyrihaximus/psr-3-callable-throwable-logger": "^1.0" }, "require-dev": { - "api-clients/test-utilities": "^5.1" + "api-clients/test-utilities": "^5.1", + "php-di/php-di": "^6.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 17a643c..a691d3b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "ae73ade6e1c8ad043a31aedb9cecece0", + "content-hash": "dcf9b07dd75835abfa487690b8cc3fa8", "packages": [ { "name": "clue/redis-protocol", @@ -1346,6 +1346,64 @@ "homepage": "https://github.com/JakubOnderka/PHP-Parallel-Lint", "time": "2015-12-15T10:42:16+00:00" }, + { + "name": "jeremeamia/SuperClosure", + "version": "2.4.0", + "source": { + "type": "git", + "url": "https://github.com/jeremeamia/super_closure.git", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "reference": "5707d5821b30b9a07acfb4d76949784aaa0e9ce9", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^1.2|^2.0|^3.0|^4.0", + "php": ">=5.4", + "symfony/polyfill-php56": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0|^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-4": { + "SuperClosure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia", + "role": "Developer" + } + ], + "description": "Serialize Closure objects, including their context and binding", + "homepage": "https://github.com/jeremeamia/super_closure", + "keywords": [ + "closure", + "function", + "lambda", + "parser", + "serializable", + "serialize", + "tokenizer" + ], + "time": "2018-03-21T22:21:57+00:00" + }, { "name": "justinrainbow/json-schema", "version": "5.2.7", @@ -2033,6 +2091,149 @@ ], "time": "2018-02-15T16:58:55+00:00" }, + { + "name": "php-di/invoker", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/Invoker.git", + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/540c27c86f663e20fe39a24cd72fa76cdb21d41a", + "reference": "540c27c86f663e20fe39a24cd72fa76cdb21d41a", + "shasum": "" + }, + "require": { + "psr/container": "~1.0" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "phpunit/phpunit": "~4.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Invoker\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Generic and extensible callable invoker", + "homepage": "https://github.com/PHP-DI/Invoker", + "keywords": [ + "callable", + "dependency", + "dependency-injection", + "injection", + "invoke", + "invoker" + ], + "time": "2017-03-20T19:28:22+00:00" + }, + { + "name": "php-di/php-di", + "version": "6.0.5", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/PHP-DI.git", + "reference": "5e8b809960d5c3bfa096a90da9a78650e80b1f0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/5e8b809960d5c3bfa096a90da9a78650e80b1f0e", + "reference": "5e8b809960d5c3bfa096a90da9a78650e80b1f0e", + "shasum": "" + }, + "require": { + "jeremeamia/superclosure": "^2.0", + "nikic/php-parser": "^2.0|^3.0|^4.0", + "php": ">=7.0.0", + "php-di/invoker": "^2.0", + "php-di/phpdoc-reader": "^2.0.1", + "psr/container": "^1.0" + }, + "provide": { + "psr/container-implementation": "^1.0" + }, + "require-dev": { + "doctrine/annotations": "~1.2", + "friendsofphp/php-cs-fixer": "^2.4", + "mnapoli/phpunit-easymock": "~1.0", + "ocramius/proxy-manager": "~2.0.2", + "phpstan/phpstan": "^0.9.2", + "phpunit/phpunit": "~6.4" + }, + "suggest": { + "doctrine/annotations": "Install it if you want to use annotations (version ~1.2)", + "ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)" + }, + "type": "library", + "autoload": { + "psr-4": { + "DI\\": "src/" + }, + "files": [ + "src/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "The dependency injection container for humans", + "homepage": "http://php-di.org/", + "keywords": [ + "PSR-11", + "container", + "container-interop", + "dependency injection", + "di", + "ioc", + "psr11" + ], + "time": "2018-09-17T15:34:44+00:00" + }, + { + "name": "php-di/phpdoc-reader", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-DI/PhpDocReader.git", + "reference": "7d0de60b9341933c8afd172a6255cd7557601e0e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/7d0de60b9341933c8afd172a6255cd7557601e0e", + "reference": "7d0de60b9341933c8afd172a6255cd7557601e0e", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "PhpDocReader\\": "src/PhpDocReader" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)", + "keywords": [ + "phpdoc", + "reflection" + ], + "time": "2018-02-18T17:39:01+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "1.0.1", @@ -3647,6 +3848,62 @@ ], "time": "2018-08-06T14:22:27+00:00" }, + { + "name": "symfony/polyfill-php56", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php56.git", + "reference": "ff208829fe1aa48ab9af356992bb7199fed551af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/ff208829fe1aa48ab9af356992bb7199fed551af", + "reference": "ff208829fe1aa48ab9af356992bb7199fed551af", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/polyfill-util": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php56\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2018-09-21T06:26:08+00:00" + }, { "name": "symfony/polyfill-php70", "version": "v1.9.0", @@ -3761,6 +4018,58 @@ ], "time": "2018-08-06T14:22:27+00:00" }, + { + "name": "symfony/polyfill-util", + "version": "v1.10.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-util.git", + "reference": "3b58903eae668d348a7126f999b0da0f2f93611c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/3b58903eae668d348a7126f999b0da0f2f93611c", + "reference": "3b58903eae668d348a7126f999b0da0f2f93611c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Util\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony utilities for portability of PHP codes", + "homepage": "https://symfony.com", + "keywords": [ + "compat", + "compatibility", + "polyfill", + "shim" + ], + "time": "2018-09-30T16:36:12+00:00" + }, { "name": "symfony/process", "version": "v4.1.6", diff --git a/tests/DiTest.php b/tests/DiTest.php new file mode 100644 index 0000000..7a91cd4 --- /dev/null +++ b/tests/DiTest.php @@ -0,0 +1,35 @@ +prophesize(LoopInterface::class); + + $logger = $this->prophesize(LoggerInterface::class); + $logger->debug('Connecting')->shouldBeCalled(); + $logger->debug('Connected')->shouldNotBeCalled(); + $logger->debug('Executing 0 waiting call(s)')->shouldNotBeCalled(); + $logger->debug('Executed all waiting calls, any new calls will be send to Redis directly')->shouldNotBeCalled(); + + $di = require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'di' . DIRECTORY_SEPARATOR . 'redis-client.php'; + $container = new Container(); + $container->set(Client::class, $di[Client::class]); + $container->set(LoopInterface::class, $loop->reveal()); + $container->set(LoggerInterface::class, $logger->reveal()); + $container->set('config.redis.dsn', self::DSN); + $client = $container->get(Client::class); + + self::assertInstanceOf(Client::class, $client); + } +} From 224710fd6b5b9704f749f16850da8ac4d770d868 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 19 Dec 2018 14:33:42 +0100 Subject: [PATCH 3/5] Drop PHP 7.1 from CI's --- .travis.yml | 12 +----------- appveyor.yml | 6 ------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04a8ccb..11a8413 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,9 @@ cache: ## Build matrix for lowest and highest possible targets matrix: include: - - php: 7.1 - env: - - qaExtended=true - php: 7.2 env: + - qaExtended=true - dropPlatform=false - php: 7.3 env: @@ -20,10 +18,6 @@ matrix: - php: nightly env: - dropPlatform=false - - php: 7.1 - env: - - dependencies=lowest - - dropPlatform=false - php: 7.2 env: - dependencies=lowest @@ -37,10 +31,6 @@ matrix: env: - dependencies=lowest - dropPlatform=false - - php: 7.1 - env: - - dependencies=highest - - dropPlatform=false - php: 7.2 env: - dependencies=highest diff --git a/appveyor.yml b/appveyor.yml index 63ace03..de1539b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,16 +6,10 @@ clone_folder: c:\projects\php-project-workspace ## Build matrix for lowest and highest possible targets environment: matrix: - - dependencies: lowest - php_ver_target: 7.1 - dependencies: lowest php_ver_target: 7.2 - - dependencies: current - php_ver_target: 7.1 - dependencies: current php_ver_target: 7.2 - - dependencies: highest - php_ver_target: 7.1 - dependencies: highest php_ver_target: 7.2 From 206fb81d919587ac8c92ddba3f69f738016c18c1 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 19 Dec 2018 14:35:59 +0100 Subject: [PATCH 4/5] Extracted the waiting client out into separate package: wyrihaximus/react-redis-waiting-client --- .php_cs | 4 +- composer.json | 4 +- composer.lock | 63 +++++++++++++++++++++------ etc/di/redis-client.php | 4 +- src/WaitingClient.php | 86 ------------------------------------- tests/RedisClient.php | 30 ------------- tests/WaitingClientTest.php | 69 ----------------------------- 7 files changed, 56 insertions(+), 204 deletions(-) delete mode 100644 src/WaitingClient.php delete mode 100644 tests/RedisClient.php delete mode 100644 tests/WaitingClientTest.php diff --git a/.php_cs b/.php_cs index afcb974..5abf409 100644 --- a/.php_cs +++ b/.php_cs @@ -1,12 +1,12 @@ \DI\factory(function (LoopInterface $loop, string $dsn, LoggerInterface $logger = null) { diff --git a/src/WaitingClient.php b/src/WaitingClient.php deleted file mode 100644 index f3ee080..0000000 --- a/src/WaitingClient.php +++ /dev/null @@ -1,86 +0,0 @@ -callQueue = new \SplQueue(); - $logger->debug('Connecting'); - $factory->createClient($dsn)->done(function (Client $client) use ($logger) { - $logger->debug('Connected'); - $this->redis = $client; - - $logger->debug('Executing ' . $this->callQueue->count() . ' waiting call(s)'); - while ($this->callQueue->count() > 0) { - $call = $this->callQueue->dequeue(); - $name = $call['name']; - $args = $call['args']; - $call['deferred']->resolve($this->redis->$name(...$args)); - } - $logger->debug('Executed all waiting calls, any new calls will be send to Redis directly'); - }, CallableThrowableLogger::create($logger)); - } - - public function __call($name, $args) - { - if ($this->redis instanceof Client) { - return $this->redis->$name(...$args); - } - - $deferred = new Deferred(); - - $this->callQueue->enqueue([ - 'deferred' => $deferred, - 'name' => $name, - 'args' => $args, - ]); - - return $deferred->promise(); - } - - public static function create(LoopInterface $loop, string $dsn, LoggerInterface $logger = null): self - { - return new self(new Factory($loop), $dsn, $logger ?? new NullLogger()); - } - - public function end() - { - // TODO: Implement end() method. - } - - public function close() - { - // TODO: Implement close() method. - } -} diff --git a/tests/RedisClient.php b/tests/RedisClient.php deleted file mode 100644 index 70133fc..0000000 --- a/tests/RedisClient.php +++ /dev/null @@ -1,30 +0,0 @@ -prophesize(LoopInterface::class); - - $logger = $this->prophesize(LoggerInterface::class); - $logger->debug('Connecting')->shouldBeCalled(); - $logger->debug('Connected')->shouldNotBeCalled(); - $logger->debug('Executing 0 waiting call(s)')->shouldNotBeCalled(); - $logger->debug('Executed all waiting calls, any new calls will be send to Redis directly')->shouldNotBeCalled(); - - WaitingClient::create($loop->reveal(), self::DSN, $logger->reveal()); - } - - public function testLogging() - { - $logger = $this->prophesize(LoggerInterface::class); - $logger->debug('Connecting')->shouldBeCalled(); - $logger->debug('Connected')->shouldBeCalled(); - $logger->debug('Executing 0 waiting call(s)')->shouldBeCalled(); - $logger->debug('Executed all waiting calls, any new calls will be send to Redis directly')->shouldBeCalled(); - - $redisFactory = $this->prophesize(Factory::class); - $redisFactory->createClient(self::DSN)->shouldbeCalled()->willReturn(resolve($this->prophesize(Client::class)->reveal())); - - new WaitingClient($redisFactory->reveal(), self::DSN, $logger->reveal()); - } - - public function testCalls() - { - $logger = $this->prophesize(LoggerInterface::class); - $logger->debug(Argument::type('string'))->shouldBeCalled(); - $logger->debug('Executing 1 waiting call(s)')->shouldBeCalled(); - - $deferred = new Deferred(); - - $redis = $this->prophesize(RedisClient::class); - $redis->incr('key')->shouldBeCalled()->willReturn(resolve(true)); - $redis->incr('sleutel')->shouldBeCalled()->willReturn(resolve(true)); - - $redisFactory = $this->prophesize(Factory::class); - $redisFactory->createClient(self::DSN)->shouldbeCalled()->willReturn($deferred->promise()); - - $waitingClient = new WaitingClient($redisFactory->reveal(), self::DSN, $logger->reveal()); - - $waitingClient->incr('key'); - - $deferred->resolve($redis->reveal()); - - $waitingClient->incr('sleutel'); - } -} From 61d8693024e7b2c6096a8599822c9cef84552617 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Wed, 19 Dec 2018 14:39:21 +0100 Subject: [PATCH 5/5] used import instead of FQFN --- etc/di/redis-client.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/etc/di/redis-client.php b/etc/di/redis-client.php index 6595002..239cc54 100644 --- a/etc/di/redis-client.php +++ b/etc/di/redis-client.php @@ -4,10 +4,12 @@ use Psr\Log\LoggerInterface; use React\EventLoop\LoopInterface; use WyriHaximus\React\Redis\WaitingClient\WaitingClient; +use function DI\factory; +use function DI\get; return [ - Client::class => \DI\factory(function (LoopInterface $loop, string $dsn, LoggerInterface $logger = null) { + Client::class => factory(function (LoopInterface $loop, string $dsn, LoggerInterface $logger = null) { return WaitingClient::create($loop, $dsn, $logger); }) - ->parameter('dsn', \DI\get('config.redis.dsn')), + ->parameter('dsn', get('config.redis.dsn')), ];