From 707377b1612910fcd92d81c1289737b6925da84c Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 5 Jan 2018 18:52:35 -0800 Subject: [PATCH 1/5] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c188f51..f21a899 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ # Model Caching for Laravel [![Gitter](https://badges.gitter.im/GeneaLabs/laravel-model-caching.svg)](https://gitter.im/GeneaLabs/laravel-model-caching?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge) [![Travis](https://img.shields.io/travis/GeneaLabs/laravel-model-caching.svg)](https://travis-ci.org/GeneaLabs/laravel-model-caching) -[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/fde269ac-c382-4d17-a647-c69ad6b9dd85.svg)](https://insight.sensiolabs.com/projects/fde269ac-c382-4d17-a647-c69ad6b9dd85) [![Scrutinizer](https://img.shields.io/scrutinizer/g/GeneaLabs/laravel-model-caching.svg)](https://scrutinizer-ci.com/g/GeneaLabs/laravel-model-caching) [![Coveralls](https://img.shields.io/coveralls/GeneaLabs/laravel-model-caching.svg)](https://coveralls.io/github/GeneaLabs/laravel-model-caching) [![GitHub (pre-)release](https://img.shields.io/github/release/GeneaLabs/laravel-model-caching/all.svg)](https://github.com/GeneaLabs/laravel-model-caching) From 4c90b9d743f8116963051bcef72790ea2098acd8 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Fri, 5 Jan 2018 18:53:44 -0800 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f21a899..1c916a1 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ information included to be actionable. Please review the Contribution Guidelines . Only PRs that meet all criterium will be accepted. -## Support Open-Source Software - Give Thanks! +## ❤️ Open-Source Software - Give ⭐️ We have included the awesome `symfony/thanks` composer package as a dev dependency. Let your OS package maintainers know you appreciate them by starring the packages you use. Simply run composer thanks after installing this package. From cc24760735014f494101ae3f9c4ef0123e9f5fde Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Tue, 9 Jan 2018 08:42:18 -0800 Subject: [PATCH 3/5] Added caching for `value()` querybuilder method --- src/CachedBuilder.php | 12 ++++++++++++ tests/Unit/CachedBuilderTest.php | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/CachedBuilder.php b/src/CachedBuilder.php index a541895..c7b4e00 100644 --- a/src/CachedBuilder.php +++ b/src/CachedBuilder.php @@ -146,4 +146,16 @@ public function sum($column) return parent::sum($column); }); } + + public function value($column) + { + if (! $this->isCachable) { + return parent::value($column); + } + + return $this->cache($this->makeCacheTags()) + ->rememberForever($this->makeCacheKey() . "-value_{$column}", function () use ($column) { + return parent::value($column); + }); + } } diff --git a/tests/Unit/CachedBuilderTest.php b/tests/Unit/CachedBuilderTest.php index fbaaa28..9f03fda 100644 --- a/tests/Unit/CachedBuilderTest.php +++ b/tests/Unit/CachedBuilderTest.php @@ -410,26 +410,27 @@ public function testSumModelResultsCreatesCache() $this->assertEquals($liveResult, $cachedResult); } + /** + * @group test + */ public function testValueModelResultsCreatesCache() { - $authors = (new Author)->with('books', 'profile') + $authorName = (new Author)->with('books', 'profile') ->value('name'); - $key = 'genealabslaravelmodelcachingtestsfixturesauthor_name-books-profile-first'; + $key = 'genealabslaravelmodelcachingtestsfixturesauthor-books-profile-value_name'; $tags = [ 'genealabslaravelmodelcachingtestsfixturesauthor', 'genealabslaravelmodelcachingtestsfixturesbook', 'genealabslaravelmodelcachingtestsfixturesprofile', ]; - $cachedResults = cache()->tags($tags) - ->get($key) - ->name; - - $liveResults = (new UncachedAuthor)->with('books', 'profile') + $cachedResult = cache()->tags($tags) + ->get($key); + $liveResult = (new UncachedAuthor)->with('books', 'profile') ->value('name'); - $this->assertEquals($authors, $cachedResults); - $this->assertEquals($liveResults, $cachedResults); + $this->assertEquals($authorName, $cachedResult); + $this->assertEquals($authorName, $liveResult); } public function testNestedRelationshipEagerLoading() From 9f76c2014765cd318bbe4a461c918b809dcc75f2 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Tue, 9 Jan 2018 08:42:30 -0800 Subject: [PATCH 4/5] Remove test group --- tests/Unit/CachedBuilderTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Unit/CachedBuilderTest.php b/tests/Unit/CachedBuilderTest.php index 9f03fda..07f421b 100644 --- a/tests/Unit/CachedBuilderTest.php +++ b/tests/Unit/CachedBuilderTest.php @@ -410,9 +410,6 @@ public function testSumModelResultsCreatesCache() $this->assertEquals($liveResult, $cachedResult); } - /** - * @group test - */ public function testValueModelResultsCreatesCache() { $authorName = (new Author)->with('books', 'profile') From 7656e00c4015ab655b10eea46b467154cd34cc43 Mon Sep 17 00:00:00 2001 From: Mike Bronner Date: Tue, 9 Jan 2018 18:50:41 -0800 Subject: [PATCH 5/5] Transition to Orchestral Testbench --- composer.json | 9 +++++--- phpunit.xml | 8 +++++-- tests/BrowserTestCase.php | 18 +++++++++++++++ tests/CreatesApplication.php | 27 ++++++++++++++--------- tests/FeatureTestCase.php | 8 +++++++ tests/TestCase.php | 8 ------- tests/Unit/CachedBuilderTest.php | 4 ++-- tests/Unit/CachedModelTest.php | 4 ++-- tests/Unit/Console/Commands/FlushTest.php | 4 ++-- tests/Unit/DisabledCachedBuilderTest.php | 4 ++-- tests/Unit/DisabledCachedModelTest.php | 4 ++-- tests/Unit/Traits/CachableTest.php | 4 ++-- tests/UnitTestCase.php | 8 +++++++ 13 files changed, 74 insertions(+), 36 deletions(-) create mode 100644 tests/BrowserTestCase.php create mode 100644 tests/FeatureTestCase.php delete mode 100644 tests/TestCase.php create mode 100644 tests/UnitTestCase.php diff --git a/composer.json b/composer.json index d8b31e1..b724a9d 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,14 @@ "require-dev": { "codedungeon/phpunit-result-printer": "^0.4.4", "fzaninotto/faker": "~1.4", - "laravel/laravel": "5.5.*", "mockery/mockery": "0.9.*", - "phpmd/phpmd": "^2.6", - "phpunit/phpunit": "5.7.*", + "orchestra/database": "^3.5", + "orchestra/testbench-browser-kit": "^3.5", + "orchestra/testbench-dusk": "3.5.x-dev@dev", + "orchestra/testbench": "^3.5", "php-coveralls/php-coveralls" : "*", + "phpmd/phpmd": "*", + "phpunit/phpunit": "*", "sebastian/phpcpd": "*", "symfony/thanks": "^1.0" }, diff --git a/phpunit.xml b/phpunit.xml index 2be4735..ebd5c58 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -13,6 +13,10 @@ syntaxCheck="false" > + + ./tests/Browser + + ./tests/Feature @@ -29,10 +33,10 @@ + - - + diff --git a/tests/BrowserTestCase.php b/tests/BrowserTestCase.php new file mode 100644 index 0000000..4e665e3 --- /dev/null +++ b/tests/BrowserTestCase.php @@ -0,0 +1,18 @@ +make(Kernel::class)->bootstrap(); - $app->make(Factory::class)->load(__DIR__ . '/database/factories'); - $app->afterResolving('migrator', function ($migrator) { - $migrator->path(__DIR__ . '/database/migrations'); - }); - $app->register(LaravelModelCachingService::class); + parent::setUp(); - return $app; + $this->withFactories(__DIR__ . '/database/factories'); + $this->loadMigrationsFrom(realpath(__DIR__ . '/database/migrations')); + } + + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + protected function getPackageProviders($app) + { + return [ + LaravelModelCachingService::class, + ConsoleServiceProvider::class, + ]; } } diff --git a/tests/FeatureTestCase.php b/tests/FeatureTestCase.php new file mode 100644 index 0000000..c68771a --- /dev/null +++ b/tests/FeatureTestCase.php @@ -0,0 +1,8 @@ +