Skip to content

Commit 30bfa27

Browse files
committed
Update to Laravel 5.8, remove previous version compatibility
1 parent 6997acb commit 30bfa27

16 files changed

+74
-152
lines changed

.travis.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,20 @@ services:
66
matrix:
77
include:
88
- php: 7.1.3
9-
env: PU_FILE=57 REDIS_HOST=127.0.0.1
10-
- php: 7.1.3
11-
env: PU_FILE=56 REDIS_HOST=127.0.0.1
12-
- php: 7.1.3
13-
env: PU_FILE=55 REDIS_HOST=127.0.0.1
14-
- php: 7.1.3
15-
env: PU_FILE=54 REDIS_HOST=127.0.0.1
16-
- php: 7.2
17-
env: PU_FILE=57 REDIS_HOST=127.0.0.1
9+
env: REDIS_HOST=127.0.0.1
1810
- php: 7.2
19-
env: PU_FILE=56 REDIS_HOST=127.0.0.1
20-
- php: 7.2
21-
env: PU_FILE=55 REDIS_HOST=127.0.0.1
22-
- php: 7.2
23-
env: PU_FILE=54 REDIS_HOST=127.0.0.1
11+
env: REDIS_HOST=127.0.0.1
12+
- php: 7.3
13+
env: REDIS_HOST=127.0.0.1
2414

2515
services:
2616
- redis-server
2717

2818
before_script:
2919
- travis_retry composer self-update
3020
- travis_retry composer install --no-interaction --prefer-source
31-
- chmod +x tests/*.sh
3221
- psql -c 'create database testing;' -U postgres
3322

34-
script:
35-
- ./tests/pu-${PU_FILE}.sh
36-
3723
after_success:
3824
- travis_retry php vendor/bin/php-coveralls -v
3925

composer.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@
1010
],
1111
"require": {
1212
"fico7489/laravel-pivot": "3.*",
13-
"illuminate/cache": "5.4 - 5.7",
14-
"illuminate/config": "5.4 - 5.7",
15-
"illuminate/console": "5.4 - 5.7",
16-
"illuminate/database": "5.4 - 5.7",
17-
"illuminate/support": "5.4 - 5.7",
18-
"php": ">=7.1.3"
13+
"illuminate/cache": "5.4 - 5.8",
14+
"illuminate/config": "5.4 - 5.8",
15+
"illuminate/console": "5.4 - 5.8",
16+
"illuminate/database": "5.4 - 5.8",
17+
"illuminate/support": "5.4 - 5.8",
18+
"php": "^7.1.3"
1919
},
2020
"require-dev": {
2121
"fzaninotto/faker": "*",
2222
"mockery/mockery": "*",
23-
"orchestra/database": "3.7.x-dev@dev",
24-
"orchestra/testbench-browser-kit": "3.7.*",
25-
"orchestra/testbench": "3.7.*",
23+
"orchestra/database": "3.8.x-dev@dev",
24+
"orchestra/testbench-browser-kit": "3.8.*",
25+
"orchestra/testbench": "3.8.*",
2626
"php-coveralls/php-coveralls" : "*",
2727
"phpmd/phpmd": "*",
28-
"phpunit/phpunit": "7.*",
28+
"phpunit/phpunit": "^7.5",
2929
"predis/predis": "*",
3030
"sebastian/phpcpd": "*",
31-
"symfony/thanks": "*",
32-
"codedungeon/phpunit-result-printer": "^0.23.4"
31+
"symfony/thanks": "*"
3332
},
3433
"autoload": {
3534
"psr-4": {

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false"
11+
stopOnFailure="true"
1212
>
1313
<testsuites>
1414
<testsuite name="Feature">
@@ -19,7 +19,7 @@
1919
</testsuite>
2020
</testsuites>
2121
<filter>
22-
<whitelist processUncoveredFilesFromWhitelist="true">
22+
<whitelist processUncoveredFilesFromWhitelist="false">
2323
<directory suffix=".php">./src</directory>
2424
</whitelist>
2525
</filter>

src/CacheKey.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Illuminate\Database\Eloquent\Model;
55
use Illuminate\Database\Query\Builder;
66
use Illuminate\Support\Collection;
7+
use Illuminate\Database\Query\Expression;
78

89
class CacheKey
910
{
@@ -40,7 +41,7 @@ public function make(
4041
$key .= $this->getOffsetClause();
4142
$key .= $this->getLimitClause();
4243
$key .= $keyDifferentiator;
43-
44+
// dump($key);
4445
return $key;
4546
}
4647

@@ -120,8 +121,6 @@ protected function getValuesClause(array $where = null) : string
120121
$values = $this->getValuesFromWhere($where);
121122
$values = $this->getValuesFromBindings($where, $values);
122123

123-
124-
125124
return "_" . $values;
126125
}
127126

@@ -140,15 +139,16 @@ protected function getValuesFromWhere(array $where) : string
140139
}
141140

142141
if (is_array(array_get($where, "values"))) {
143-
return implode("_", $where["values"]);
142+
return implode("_", collect($where["values"])->flatten()->toArray());
144143
}
145144

146145
return array_get($where, "value", "");
147146
}
148147

149148
protected function getValuesFromBindings(array $where, string $values) : string
150149
{
151-
if (! $values && ($this->query->bindings["where"][$this->currentBinding] ?? false)) {
150+
// if (! $values && ($this->query->bindings["where"][$this->currentBinding] ?? false)) {
151+
if ($this->query->bindings["where"][$this->currentBinding] ?? false) {
152152
$values = $this->query->bindings["where"][$this->currentBinding];
153153
$this->currentBinding++;
154154

@@ -169,8 +169,7 @@ protected function getWhereClauses(array $wheres = []) : string
169169
$value .= $this->getNestedClauses($where);
170170
$value .= $this->getColumnClauses($where);
171171
$value .= $this->getRawClauses($where);
172-
$value .= $this->getInClauses($where);
173-
$value .= $this->getNotInClauses($where);
172+
$value .= $this->getInAndNotInClauses($where);
174173
$value .= $this->getOtherClauses($where, $carry);
175174

176175
return $value;
@@ -207,23 +206,40 @@ protected function getInClauses(array $where) : string
207206
return "-{$where["column"]}_in{$values}";
208207
}
209208

210-
protected function getNotInClauses(array $where) : string
209+
protected function getInAndNotInClauses(array $where) : string
211210
{
212-
if (! in_array($where["type"], ["NotIn"])) {
211+
if (! in_array($where["type"], ["In", "NotIn"])) {
213212
return "";
214213
}
215214

215+
$type = strtolower($where["type"]);
216+
$subquery = $this->getValuesFromWhere($where);
217+
$values = collect($this->query->bindings["where"][$this->currentBinding]);
216218
$this->currentBinding++;
217-
$values = $this->recursiveImplode($where["values"], "_");
219+
$subquery = collect(vsprintf(str_replace("?", "%s", $subquery), $values->toArray()));
220+
$values = $this->recursiveImplode($subquery->toArray(), "_");
218221

219-
return "-{$where["column"]}_not_in{$values}";
222+
return "-{$where["column"]}_{$type}{$values}";
220223
}
221224

222225
protected function recursiveImplode(array $items, string $glue = ",") : string
223226
{
224227
$result = "";
225228

226229
foreach ($items as $value) {
230+
if ($value instanceof Expression) {
231+
$value = $value->getValue();
232+
}
233+
234+
if (is_string($value)) {
235+
$value = str_replace('"', '', $value);
236+
$value = explode(" ", $value);
237+
238+
if (count($value) === 1) {
239+
$value = $value[0];
240+
}
241+
}
242+
227243
if (is_array($value)) {
228244
$result .= $this->recursiveImplode($value, $glue);
229245

src/CacheTags.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function make() : array
3737
->prepend($this->getTagName())
3838
->values()
3939
->toArray();
40-
40+
// dump($tags);
4141
return $tags;
4242
}
4343

tests/CreatesApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function cache()
2424
return $cache;
2525
}
2626

27-
public function setUp()
27+
public function setUp() : void
2828
{
2929
parent::setUp();
3030

tests/Feature/PaginationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public function testPaginationProvidesDifferentLinksOnDifferentPages()
99
{
1010
if (starts_with(app()->version(), "5.6")
1111
|| starts_with(app()->version(), "5.7")
12+
|| starts_with(app()->version(), "5.8")
1213
) {
1314
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
1415
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
@@ -40,6 +41,7 @@ public function testAdvancedPagination()
4041
{
4142
if (starts_with(app()->version(), "5.6")
4243
|| starts_with(app()->version(), "5.7")
44+
|| starts_with(app()->version(), "5.8")
4345
) {
4446
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
4547
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
@@ -64,6 +66,7 @@ public function testCustomPagination()
6466
{
6567
if (starts_with(app()->version(), "5.6")
6668
|| starts_with(app()->version(), "5.7")
69+
|| starts_with(app()->version(), "5.8")
6770
) {
6871
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
6972
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';

tests/Integration/CachedBuilder/PaginateTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function testPaginationReturnsCorrectLinks()
4646
{
4747
if (starts_with(app()->version(), "5.6")
4848
|| starts_with(app()->version(), "5.7")
49+
|| starts_with(app()->version(), "5.8")
4950
) {
5051
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
5152
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
@@ -83,6 +84,7 @@ public function testPaginationWithOptionsReturnsCorrectLinks()
8384
{
8485
if (starts_with(app()->version(), "5.6")
8586
|| starts_with(app()->version(), "5.7")
87+
|| starts_with(app()->version(), "5.8")
8688
) {
8789
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
8890
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
@@ -120,6 +122,7 @@ public function testPaginationWithCustomOptionsReturnsCorrectLinks()
120122
{
121123
if (starts_with(app()->version(), "5.6")
122124
|| starts_with(app()->version(), "5.7")
125+
|| starts_with(app()->version(), "5.8")
123126
) {
124127
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
125128
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';

tests/Integration/CachedBuilder/WhereJsonContainsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function getEnvironmentSetUp($app)
2727
$app['config']->set('database.default', 'pgsql');
2828
}
2929

30-
public function setUp()
30+
public function setUp() : void
3131
{
3232
parent::setUp();
3333

tests/Integration/CachedBuilder/WhereNotInTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WhereNotInTest extends IntegrationTestCase
1919
{
2020
public function testWhereNotInQuery()
2121
{
22-
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_not_in_1_2_3_4');
22+
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-author_id_notin_1_2_3_4');
2323
$tags = [
2424
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
2525
];
@@ -44,7 +44,7 @@ public function testWhereNotInQuery()
4444

4545
public function testWhereNotInResults()
4646
{
47-
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_not_in_1_2');
47+
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2');
4848
$tags = [
4949
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
5050
];
@@ -65,11 +65,10 @@ public function testWhereNotInResults()
6565

6666
public function testWhereNotInSubquery()
6767
{
68-
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notinsub_bookbooks:-id_<_10');
68+
$key = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_select_id_from_authors_where_id_<_10');
6969
$tags = [
7070
'genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook',
7171
];
72-
7372
$results = (new Book)
7473
->whereNotIn("id", function ($query) {
7574
$query->select("id")->from("authors")->where("id", "<", 10);

tests/Integration/CachedBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public function testWhereDatesResults()
677677

678678
public function testHashCollision()
679679
{
680-
$key1 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_not_in_1_2');
680+
$key1 = sha1('genealabs:laravel-model-caching:testing::memory::books:genealabslaravelmodelcachingtestsfixturesbook-id_notin_1_2');
681681
$tags1 = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesbook'];
682682
$books = (new Book)
683683
->whereNotIn('id', [1, 2])

tests/Integration/Console/Commands/FlushTest.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
44
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
5-
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
6-
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
75
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
86
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
97
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\PrefixedAuthor;
108
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
11-
use Illuminate\Foundation\Testing\RefreshDatabase;
129

1310
class FlushTest extends IntegrationTestCase
1411
{
15-
public function setUp()
12+
public function setUp() : void
1613
{
1714
parent::setUp();
1815

@@ -31,7 +28,9 @@ public function testGivenModelIsFlushed()
3128
->cache
3229
->tags($tags)
3330
->get($key)['value'];
34-
$result = $this->artisan('modelCache:clear', ['--model' => Author::class]);
31+
$result = $this
32+
->artisan('modelCache:clear', ['--model' => Author::class])
33+
->execute();
3534
$flushedResults = $this
3635
->cache
3736
->tags($tags)
@@ -54,7 +53,9 @@ public function testExtendedModelIsFlushed()
5453
->cache
5554
->tags($tags)
5655
->get($key)['value'];
57-
$result = $this->artisan('modelCache:clear', ['--model' => PrefixedAuthor::class]);
56+
$result = $this
57+
->artisan('modelCache:clear', ['--model' => PrefixedAuthor::class])
58+
->execute();
5859
$flushedResults = $this
5960
->cache
6061
->tags($tags)
@@ -78,9 +79,10 @@ public function testGivenModelWithRelationshipIsFlushed()
7879
->tags($tags)
7980
->get($key)['value'];
8081
$result = $this->artisan(
81-
'modelCache:clear',
82-
['--model' => Author::class]
83-
);
82+
'modelCache:clear',
83+
['--model' => Author::class]
84+
)
85+
->execute();
8486
$flushedResults = $this->cache
8587
->tags($tags)
8688
->get($key)['value'];
@@ -93,9 +95,10 @@ public function testGivenModelWithRelationshipIsFlushed()
9395
public function testNonCachedModelsCannotBeFlushed()
9496
{
9597
$result = $this->artisan(
96-
'modelCache:clear',
97-
['--model' => UncachedAuthor::class]
98-
);
98+
'modelCache:clear',
99+
['--model' => UncachedAuthor::class]
100+
)
101+
->execute();
99102

100103
$this->assertEquals($result, 1);
101104
}
@@ -126,7 +129,8 @@ public function testAllModelsAreFlushed()
126129
$this->assertNotEmpty($cachedBooks);
127130
$this->assertNotEmpty($cachedStores);
128131

129-
$this->artisan('modelCache:clear');
132+
$this->artisan('modelCache:clear')
133+
->execute();
130134

131135
$key = sha1('genealabs:laravel-model-caching:testing::memory::authors:genealabslaravelmodelcachingtestsfixturesauthor');
132136
$tags = ['genealabs:laravel-model-caching:testing::memory::genealabslaravelmodelcachingtestsfixturesauthor'];

0 commit comments

Comments
 (0)