11<?php namespace GeneaLabs \LaravelModelCaching \Tests \Integration \CachedBuilder ;
22
3+ use DateInterval ;
4+ use DateTime ;
35use GeneaLabs \LaravelModelCaching \Tests \Fixtures \Book ;
46use GeneaLabs \LaravelModelCaching \Tests \Fixtures \UncachedBook ;
57use GeneaLabs \LaravelModelCaching \Tests \IntegrationTestCase ;
68
79class DateTimeTest extends IntegrationTestCase
810{
9- public function testDateWhereCreatesCorrectCacheKey ()
11+ public function testWhereClauseWorksWithCarbonDate ()
1012 {
11- $ dateTime = now ()->subYears (10 )-> toDateString () ;
13+ $ dateTime = now ()->subYears (10 );
1214 $ key = sha1 ("genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:books:genealabslaravelmodelcachingtestsfixturesbook-publish_at_>_ {$ dateTime }" );
1315 $ tags = [
1416 "genealabs:laravel-model-caching:testing: {$ this ->testingSqlitePath }testing.sqlite:genealabslaravelmodelcachingtestsfixturesbook " ,
@@ -30,4 +32,31 @@ public function testDateWhereCreatesCorrectCacheKey()
3032 $ this ->assertNotEmpty ($ cachedResults );
3133 $ this ->assertNotEmpty ($ liveResults );
3234 }
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+ }
3362}
0 commit comments