@@ 50-68 (lines=19) @@ | ||
47 | $this->assertEquals($author->toArray(), $uncachedAuthor->toArray()); |
|
48 | } |
|
49 | ||
50 | public function testGetWithFieldArrayCachesResults() |
|
51 | { |
|
52 | $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor_id_name-authors.deleted_at_null"); |
|
53 | $tags = [ |
|
54 | "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor", |
|
55 | ]; |
|
56 | ||
57 | $authors = (new Author) |
|
58 | ->get(["id", "name"]); |
|
59 | $cachedResults = $this |
|
60 | ->cache() |
|
61 | ->tags($tags) |
|
62 | ->get($key)['value']; |
|
63 | $liveResults = (new UncachedAuthor) |
|
64 | ->get(["id", "name"]); |
|
65 | ||
66 | $this->assertEquals($liveResults->pluck("id"), $authors->pluck("id")); |
|
67 | $this->assertEquals($liveResults->pluck("id"), $cachedResults->pluck("id")); |
|
68 | } |
|
69 | ||
70 | public function testGetWithFieldStringCachesResults() |
|
71 | { |
@@ 586-605 (lines=20) @@ | ||
583 | $this->assertNull($deletedAuthor); |
|
584 | } |
|
585 | ||
586 | public function testWhereBetweenIdsResults() |
|
587 | { |
|
588 | $books = (new Book) |
|
589 | ->whereBetween('price', [5, 10]) |
|
590 | ->get(); |
|
591 | $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-price_between_5_10"); |
|
592 | $tags = [ |
|
593 | "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
|
594 | ]; |
|
595 | ||
596 | $cachedResults = $this->cache() |
|
597 | ->tags($tags) |
|
598 | ->get($key)['value']; |
|
599 | $liveResults = (new UncachedAuthor) |
|
600 | ->whereBetween('price', [5, 10]) |
|
601 | ->get(); |
|
602 | ||
603 | $this->assertTrue($cachedResults->diffKeys($books)->isEmpty()); |
|
604 | $this->assertTrue($liveResults->diffKeys($books)->isEmpty()); |
|
605 | } |
|
606 | ||
607 | public function testWhereBetweenDatesResults() |
|
608 | { |
|
@@ 607-626 (lines=20) @@ | ||
604 | $this->assertTrue($liveResults->diffKeys($books)->isEmpty()); |
|
605 | } |
|
606 | ||
607 | public function testWhereBetweenDatesResults() |
|
608 | { |
|
609 | $books = (new Book) |
|
610 | ->whereBetween('created_at', ['2018-01-01', '2018-12-31']) |
|
611 | ->get(); |
|
612 | $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-created_at_between_2018-01-01_2018-12-31"); |
|
613 | $tags = [ |
|
614 | "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
|
615 | ]; |
|
616 | ||
617 | $cachedResults = $this->cache() |
|
618 | ->tags($tags) |
|
619 | ->get($key)['value']; |
|
620 | $liveResults = (new UncachedAuthor) |
|
621 | ->whereBetween('price', [5, 10]) |
|
622 | ->get(); |
|
623 | ||
624 | $this->assertTrue($cachedResults->diffKeys($books)->isEmpty()); |
|
625 | $this->assertTrue($liveResults->diffKeys($books)->isEmpty()); |
|
626 | } |
|
627 | ||
628 | public function testWhereDatesResults() |
|
629 | { |
|
@@ 628-647 (lines=20) @@ | ||
625 | $this->assertTrue($liveResults->diffKeys($books)->isEmpty()); |
|
626 | } |
|
627 | ||
628 | public function testWhereDatesResults() |
|
629 | { |
|
630 | $books = (new Book) |
|
631 | ->whereDate('created_at', '>=', '2018-01-01') |
|
632 | ->get(); |
|
633 | $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-created_at_>=_2018-01-01"); |
|
634 | $tags = [ |
|
635 | "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook", |
|
636 | ]; |
|
637 | ||
638 | $cachedResults = $this->cache() |
|
639 | ->tags($tags) |
|
640 | ->get($key)['value']; |
|
641 | $liveResults = (new UncachedAuthor) |
|
642 | ->whereBetween('price', [5, 10]) |
|
643 | ->get(); |
|
644 | ||
645 | $this->assertTrue($cachedResults->diffKeys($books)->isEmpty()); |
|
646 | $this->assertTrue($liveResults->diffKeys($books)->isEmpty()); |
|
647 | } |
|
648 | ||
649 | public function testHashCollision() |
|
650 | { |