1
1
<?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration \CachedBuilder ;
2
2
3
+ use DateInterval ;
4
+ use DateTime ;
3
5
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
4
6
use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedBook ;
5
7
use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
6
8
7
9
class DateTimeTest extends IntegrationTestCase
8
10
{
9
- public function testDateWhereCreatesCorrectCacheKey ()
11
+ public function testWhereClauseWorksWithCarbonDate ()
10
12
{
11
- $ dateTime = now ()->subYears (10 )-> toDateString () ;
13
+ $ dateTime = now ()->subYears (10 );
12
14
$ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-publish_at_>_ {$ dateTime }" );
13
15
$ tags = [
14
16
"genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook " ,
@@ -30,4 +32,31 @@ public function testDateWhereCreatesCorrectCacheKey()
30
32
$ this ->assertNotEmpty ($ cachedResults );
31
33
$ this ->assertNotEmpty ($ liveResults );
32
34
}
35
+
36
+ public function testWhereClauseWorksWithDateTimeObject ()
37
+ {
38
+ $ dateTime = (new DateTime ('@ ' . time ()))
39
+ ->sub (new DateInterval ("P10Y " ));
40
+ $ dateTimeString = $ dateTime ->format ("Y-m-d-H-i-s " );
41
+ $ key = sha1 ("genealabs:laravel-model-caching:testing:/Users/mike/Developer/Sites/laravel-model-caching/tests/database/testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-publish_at_>_ {$ dateTimeString }" );
42
+ $ tags = [
43
+ "genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook " ,
44
+ ];
45
+
46
+ $ results = (new Book )
47
+ ->where ("publish_at " , "> " , $ dateTime )
48
+ ->get ();
49
+ $ cachedResults = $ this ->cache ()
50
+ ->tags ($ tags )
51
+ ->get ($ key )['value ' ];
52
+ $ liveResults = (new UncachedBook )
53
+ ->where ("publish_at " , "> " , $ dateTime )
54
+ ->get ();
55
+
56
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ results ->pluck ("id " ));
57
+ $ this ->assertEquals ($ liveResults ->pluck ("id " ), $ cachedResults ->pluck ("id " ));
58
+ $ this ->assertNotEmpty ($ results );
59
+ $ this ->assertNotEmpty ($ cachedResults );
60
+ $ this ->assertNotEmpty ($ liveResults );
61
+ }
33
62
}
0 commit comments