Skip to content

Commit b9960b6

Browse files
committed
WIP- Add test for eagerload closures.
1 parent b863a1b commit b9960b6

File tree

9 files changed

+66
-16
lines changed

9 files changed

+66
-16
lines changed

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for XDebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9000,
12+
"pathMappings": {
13+
"/home/vagrant/Sites/ens": "/Users/mike/Developer/Sites/ens"
14+
}
15+
}
16+
]
17+
}

composer.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
}
1010
],
1111
"require": {
12-
"genealabs/laravel-pivot-events": "*",
13-
"illuminate/cache": "5.8 - 6.0",
14-
"illuminate/config": "5.8 - 6.0",
15-
"illuminate/console": "5.8 - 6.0",
16-
"illuminate/container": "5.8 - 6.0",
17-
"illuminate/database": "5.8 - 6.0",
18-
"illuminate/support": "5.8 - 6.0",
19-
"illuminate/http": "5.8 - 6.0"
12+
"genealabs/laravel-pivot-events": "^0.2.1",
13+
"illuminate/cache": "^6.0",
14+
"illuminate/config": "^6.0",
15+
"illuminate/console": "^6.0",
16+
"illuminate/container": "^6.0",
17+
"illuminate/database": "^6.0",
18+
"illuminate/http": "^6.0",
19+
"illuminate/support": "^6.0"
2020
},
2121
"require-dev": {
22-
"fzaninotto/faker": "*",
22+
"fzaninotto/faker": "^1.4",
2323
"mockery/mockery": "*",
24-
"orchestra/testbench-browser-kit": "3.9.x-dev@dev",
25-
"orchestra/testbench": "3.9.x-dev@dev",
24+
"orchestra/testbench-browser-kit": "^4.0",
25+
"orchestra/testbench": "^4.0",
2626
"php-coveralls/php-coveralls" : "*",
2727
"phpmd/phpmd": "*",
28-
"phpunit/phpunit": "*",
28+
"phpunit/phpunit": "^8.0",
2929
"predis/predis": "*",
3030
"sebastian/phpcpd": "*",
3131
"symfony/thanks": "*"
@@ -50,7 +50,5 @@
5050
"GeneaLabs\\LaravelModelCaching\\Providers\\Service"
5151
]
5252
}
53-
},
54-
"minimum-stability": "dev",
55-
"prefer-stable": true
53+
}
5654
}

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
<env name="QUEUE_DRIVER" value="sync"/>
3636
<env name="DB_CONNECTION" value="sqlite"/>
3737
<env name="DB_DATABASE" value=":memory:"/>
38+
<env name="REDIS_HOST" value="192.168.10.10"/>
3839
</php>
3940
</phpunit>

tests/Fixtures/Author.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public function scopeNameStartsWith(Builder $query, string $startOfName) : Build
4848
{
4949
return $query->where("name", "LIKE", "{$startOfName}%");
5050
}
51+
52+
public function scopeBooksStartWith(Builder $query, string $startOfName) : Builder
53+
{
54+
return $query->where("name", "LIKE", "{$startOfName}%");
55+
}
5156
}

tests/Fixtures/Book.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
22

33
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
4+
use Illuminate\Database\Eloquent\Builder;
45
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Database\Eloquent\Relations\BelongsTo;
67
use Illuminate\Database\Eloquent\Relations\MorphMany;
@@ -53,4 +54,9 @@ public function uncachedStores() : BelongsToMany
5354
{
5455
return $this->belongsToMany(UncachedStore::class, "book_store", "book_id", "store_id");
5556
}
57+
58+
public function scopeStartsWith(Builder $query, string $startOfName) : Builder
59+
{
60+
return $query->where("name", "LIKE", "{$startOfName}%");
61+
}
5662
}

tests/Integration/CachedBuilder/ScopeTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorBeginsWithA;
77
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\AuthorWithInlineGlobalScope;
88
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthorWithInlineGlobalScope;
9+
use Illuminate\Database\Eloquent\Relations\HasMany;
910

1011
class ScopeTest extends IntegrationTestCase
1112
{
@@ -97,4 +98,24 @@ public function testInlineGlobalScopesAreCached()
9798
$this->assertTrue($cachedResults->contains($author));
9899
$this->assertTrue($liveResults->contains($author));
99100
}
101+
102+
public function testLocalScopesInRelationship()
103+
{
104+
$first = "A";
105+
$second = "B";
106+
$authors1 = (new Author)
107+
->with(['books' => static function (HasMany $model) use ($first) {
108+
$model->startsWith($first);
109+
}])
110+
->get();
111+
$authors2 = (new Author)
112+
->disableModelCaching()
113+
->with(['books' => static function (HasMany $model) use ($second) {
114+
$model->startsWith($second);
115+
}])
116+
->get();
117+
118+
// $this->assertNotEquals($authors1, $authors2);
119+
$this->markTestSkipped();
120+
}
100121
}

tests/Integration/CachedBuilder/WhereJsonContainsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ protected function getEnvironmentSetUp($app)
1414
parent::getEnvironmentSetUp($app);
1515

1616
$app['config']->set('database.default', 'pgsql');
17+
$app['config']->set('database.connections.pgsql.host', "192.168.10.10");
1718
$app['config']->set('database.connections.pgsql.database', "testing");
18-
$app['config']->set('database.connections.pgsql.username', "mike");
19+
$app['config']->set('database.connections.pgsql.username', "homestead");
20+
$app['config']->set('database.connections.pgsql.password', "secret");
1921
}
2022

2123
public function setUp() : void

tests/database/baseline.sqlite

-16 KB
Binary file not shown.

tests/database/testing.sqlite

-16 KB
Binary file not shown.

0 commit comments

Comments
 (0)