From d58f264c3303d5c892f737ff718adebfacd41a16 Mon Sep 17 00:00:00 2001 From: Pavel Sheiman Date: Mon, 27 Mar 2017 23:21:04 +0300 Subject: [PATCH 1/7] * fix: replace $app->share() calls with $app->singleton() --- src/Spiritix/LadaCache/LadaCacheServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php index 169c4d2..feff5b7 100644 --- a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php +++ b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php @@ -135,15 +135,15 @@ private function registerConnections() */ private function registerCommand() { - $this->app['command.lada-cache.flush'] = $this->app->share(function() { + $this->app->singleton('command.lada-cache.flush', function() { return new FlushCommand(); }); - $this->app['command.lada-cache.enable'] = $this->app->share(function() { + $this->app->singleton('command.lada-cache.enable', function() { return new EnableCommand(); }); - $this->app['command.lada-cache.disable'] = $this->app->share(function() { + $this->app->singleton('command.lada-cache.disable', function() { return new DisableCommand(); }); From ea2aab1ae68666a627967d237724380aaa135d38 Mon Sep 17 00:00:00 2001 From: Pavel Sheiman Date: Mon, 27 Mar 2017 23:54:39 +0300 Subject: [PATCH 2/7] * fix: compatibility with L5.4 service resolution --- src/Spiritix/LadaCache/LadaCacheServiceProvider.php | 2 +- src/Spiritix/LadaCache/Redis.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php index feff5b7..25cf035 100644 --- a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php +++ b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php @@ -85,7 +85,7 @@ public function provides() private function registerSingletons() { $this->app->singleton('lada.redis', function($app) { - return new Redis(config('lada-cache.prefix')); + return new Redis(); }); $this->app->singleton('lada.cache', function($app) { diff --git a/src/Spiritix/LadaCache/Redis.php b/src/Spiritix/LadaCache/Redis.php index 15f59e2..0c59b0f 100644 --- a/src/Spiritix/LadaCache/Redis.php +++ b/src/Spiritix/LadaCache/Redis.php @@ -35,7 +35,7 @@ class Redis */ public function __construct($prefix) { - $this->prefix = (string) $prefix; + $this->prefix = config('lada-cache.prefix'); } /** From 93fc261916bf8bca1f698e2d0e7c42dddc9ed00f Mon Sep 17 00:00:00 2001 From: Pavel Sheiman Date: Mon, 27 Mar 2017 23:54:39 +0300 Subject: [PATCH 3/7] * fix: compatibility with L5.4 service resolution --- src/Spiritix/LadaCache/LadaCacheServiceProvider.php | 2 +- src/Spiritix/LadaCache/Redis.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php index feff5b7..25cf035 100644 --- a/src/Spiritix/LadaCache/LadaCacheServiceProvider.php +++ b/src/Spiritix/LadaCache/LadaCacheServiceProvider.php @@ -85,7 +85,7 @@ public function provides() private function registerSingletons() { $this->app->singleton('lada.redis', function($app) { - return new Redis(config('lada-cache.prefix')); + return new Redis(); }); $this->app->singleton('lada.cache', function($app) { diff --git a/src/Spiritix/LadaCache/Redis.php b/src/Spiritix/LadaCache/Redis.php index 15f59e2..21d21c7 100644 --- a/src/Spiritix/LadaCache/Redis.php +++ b/src/Spiritix/LadaCache/Redis.php @@ -31,11 +31,10 @@ class Redis /** * Initialize Redis handler. * - * @param string $prefix */ - public function __construct($prefix) + public function __construct() { - $this->prefix = (string) $prefix; + $this->prefix = config('lada-cache.prefix'); } /** From 23c22bb1ced6772834a6d3c6ab78486dd0120913 Mon Sep 17 00:00:00 2001 From: Pavel Sheiman Date: Tue, 28 Mar 2017 16:13:03 +0300 Subject: [PATCH 4/7] * fix: app->make() does not support additional arguments in 5.4 --- src/Spiritix/LadaCache/QueryHandler.php | 12 ++++++------ tests/IntegrationTest.php | 4 ++-- tests/TaggerTest.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Spiritix/LadaCache/QueryHandler.php b/src/Spiritix/LadaCache/QueryHandler.php index d4b1f75..75e146a 100644 --- a/src/Spiritix/LadaCache/QueryHandler.php +++ b/src/Spiritix/LadaCache/QueryHandler.php @@ -89,10 +89,10 @@ public function cacheQuery($queryClosure) $this->constructCollector(); /* @var Reflector $reflector */ - $reflector = app()->make(Reflector::class, [$this->builder]); + $reflector = new Reflector($this->builder); /* @var Manager $manager */ - $manager = app()->make(Manager::class, [$reflector]); + $manager = new Manager($reflector); // If cache is disabled, abort already here to save time if (!$manager->shouldCache()) { @@ -100,10 +100,10 @@ public function cacheQuery($queryClosure) } /* @var Hasher $hasher */ - $hasher = app()->make(Hasher::class, [$reflector]); + $hasher = new Hasher($reflector); /* @var Tagger $tagger */ - $tagger = app()->make(Tagger::class, [$reflector]); + $tagger = new Tagger($reflector); $result = null; $key = $hasher->getHash(); @@ -138,10 +138,10 @@ public function invalidateQuery($statementType, $values = []) $this->constructCollector(); /* @var Reflector $reflector */ - $reflector = app()->make(Reflector::class, [$this->builder, $statementType, $values]); + $reflector = new Reflector($this->builder, $statementType, $values); /* @var Tagger $tagger */ - $tagger = app()->make(Tagger::class, [$reflector]); + $tagger = new Tagger($reflector); $hashes = $this->invalidator->invalidate($tagger->getTags()); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 03eb9f9..47bb199 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -114,10 +114,10 @@ public function testTruncate() private function hasQuery(QueryBuilder $builder) { /* @var Reflector $reflector */ - $reflector = app()->make(Reflector::class, [$builder]); + $reflector = new Reflector($builder); /* @var Hasher $hasher */ - $hasher = app()->make(Hasher::class, [$reflector]); + $hasher = new Hasher($reflector); return $this->cache->has($hasher->getHash()); } diff --git a/tests/TaggerTest.php b/tests/TaggerTest.php index 913fe01..392f6e2 100644 --- a/tests/TaggerTest.php +++ b/tests/TaggerTest.php @@ -611,10 +611,10 @@ private function getRowTag($table, $rowId) private function getTags($tableBuilder, $sqlOperation = Reflector::QUERY_TYPE_SELECT, $values = []) { /** @var Reflector $reflector */ - $reflector = app(Reflector::class, [$tableBuilder->getQuery(), $sqlOperation, $values]); + $reflector = new Reflector($tableBuilder->getQuery(), $sqlOperation, $values); /** @var Tagger $tagger */ - $tagger = app(Tagger::class, [$reflector]); + $tagger = new Tagger($reflector); return $tagger->getTags(); } From 3673e5e07b621428d90e2a2fdefa64a30ae75ce0 Mon Sep 17 00:00:00 2001 From: Florian Heller Date: Wed, 19 Jul 2017 18:47:35 +0200 Subject: [PATCH 5/7] Added orchestra/database (see: https://github.com/orchestral/testbench#using-migrations) --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 439c562..4af7f45 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "phpunit/phpunit": "~5.0", "codeclimate/php-test-reporter": "dev-master", "orchestra/testbench": "~3.0", - "laracasts/TestDummy": "~2.3" + "laracasts/TestDummy": "~2.3", + "orchestra/database": "~3.1" }, "suggest": { "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol", From 68c8264bdad5b57d7660d2f56fbdea3ce79b9a2f Mon Sep 17 00:00:00 2001 From: Florian Heller Date: Wed, 19 Jul 2017 18:48:32 +0200 Subject: [PATCH 6/7] Switched from artisan to loadMigrationsFrom command to continue using --realpath option (see: https://github.com/orchestral/testbench#using-migrations) --- tests/TestCase.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/TestCase.php b/tests/TestCase.php index ecde9b7..cb061f6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\DB; use Laracasts\TestDummy\Factory; use Spiritix\LadaCache\LadaCacheServiceProvider; +use Orchestra\Database\ConsoleServiceProvider; class TestCase extends \Orchestra\Testbench\TestCase { @@ -14,9 +15,9 @@ public function setUp() { parent::setUp(); - $this->artisan('migrate', [ + $this->loadMigrationsFrom([ '--database' => 'testing', - '--realpath' => realpath(__DIR__ . '/../database/migrations'), + '--realpath' => realpath(__DIR__.'/../database/migrations'), ]); $this->factory = new Factory(__DIR__ . '/../database/factories'); @@ -33,7 +34,10 @@ public function tearDown() protected function getPackageProviders($app) { - return [LadaCacheServiceProvider::class]; + return [ + LadaCacheServiceProvider::class, + ConsoleServiceProvider::class + ]; } protected function getEnvironmentSetUp($app) From a1cf7e098b4e6418f70e0cca46cd52cdb28b0efa Mon Sep 17 00:00:00 2001 From: Florian Heller Date: Wed, 19 Jul 2017 18:50:21 +0200 Subject: [PATCH 7/7] Changed test setUp to match changes by qodeboy (The setup now sets the prefix after instantiation of the Redis class) --- tests/RedisTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 5ee7ab2..6a3ac39 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -12,7 +12,8 @@ public function setUp() { parent::setUp(); - $this->redis = new Redis('prefix:'); + $this->redis = new Redis(); + $this->redis->prefix = 'prefix:'; } public function testPrefix()