Skip to content

Commit 3e7a70c

Browse files
authored
Merge pull request #329 from dmason30/add-where-json-length-test
Add whereJsonLength test
2 parents 3a7c951 + 8c784a6 commit 3e7a70c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
5+
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
6+
7+
class WhereJsonLengthTest extends IntegrationTestCase
8+
{
9+
public function testWithInUsingCollectionQueryNoOperator()
10+
{
11+
$length = 2;
12+
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->tags_=_$length-authors.deleted_at_null");
13+
$tags = [
14+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
15+
];
16+
17+
$authors = (new Author)->whereJsonLength("finances->tags", $length)->get();
18+
$liveResults = (new UncachedAuthor)->whereJsonLength("finances->tags", $length)->get();
19+
20+
$cachedResults = $this
21+
->cache()
22+
->tags($tags)
23+
->get($key)['value'];
24+
25+
$this->assertCount(10, $liveResults);
26+
$this->assertCount(10, $cachedResults);
27+
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id"));
28+
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
29+
}
30+
31+
public function testWithInUsingCollectionQueryWithOperator()
32+
{
33+
$key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-finances->tags_>_1-authors.deleted_at_null");
34+
$tags = [
35+
"genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
36+
];
37+
38+
$authors = (new Author)->whereJsonLength("finances->tags", '>', 1)->get();
39+
$liveResults = (new UncachedAuthor)->whereJsonLength("finances->tags", '>', 1)->get();
40+
41+
$cachedResults = $this
42+
->cache()
43+
->tags($tags)
44+
->get($key)['value'];
45+
46+
$this->assertCount(10, $liveResults);
47+
$this->assertCount(10, $cachedResults);
48+
$this->assertEquals($liveResults->pluck("id"), $authors->pluck("id"));
49+
$this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id"));
50+
}
51+
}

0 commit comments

Comments
 (0)