6
6
use Illuminate \Cache \DatabaseStore ;
7
7
use Illuminate \Database \Connection ;
8
8
use Illuminate \Database \PostgresConnection ;
9
+ use Illuminate \Database \SQLiteConnection ;
9
10
use Mockery as m ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
use stdClass ;
@@ -68,6 +69,17 @@ public function testValueIsReturnedOnPostgres()
68
69
$ this ->assertSame ('bar ' , $ store ->get ('foo ' ));
69
70
}
70
71
72
+ public function testValueIsReturnedOnSqlite ()
73
+ {
74
+ $ store = $ this ->getSqliteStore ();
75
+ $ table = m::mock (stdClass::class);
76
+ $ store ->getConnection ()->shouldReceive ('table ' )->once ()->with ('table ' )->andReturn ($ table );
77
+ $ table ->shouldReceive ('whereIn ' )->once ()->with ('key ' , ['prefixfoo ' ])->andReturn ($ table );
78
+ $ table ->shouldReceive ('get ' )->once ()->andReturn (collect ([(object ) ['key ' => 'prefixfoo ' , 'value ' => base64_encode (serialize ("\0bar \0" )), 'expiration ' => 999999999999999 ]]));
79
+
80
+ $ this ->assertSame ("\0bar \0" , $ store ->get ('foo ' ));
81
+ }
82
+
71
83
public function testValueIsUpserted ()
72
84
{
73
85
$ store = $ this ->getMockBuilder (DatabaseStore::class)->onlyMethods (['getTime ' ])->setConstructorArgs ($ this ->getMocks ())->getMock ();
@@ -92,6 +104,18 @@ public function testValueIsUpsertedOnPostgres()
92
104
$ this ->assertTrue ($ result );
93
105
}
94
106
107
+ public function testValueIsUpsertedOnSqlite ()
108
+ {
109
+ $ store = $ this ->getMockBuilder (DatabaseStore::class)->onlyMethods (['getTime ' ])->setConstructorArgs ($ this ->getSqliteMocks ())->getMock ();
110
+ $ table = m::mock (stdClass::class);
111
+ $ store ->getConnection ()->shouldReceive ('table ' )->once ()->with ('table ' )->andReturn ($ table );
112
+ $ store ->expects ($ this ->once ())->method ('getTime ' )->willReturn (1 );
113
+ $ table ->shouldReceive ('upsert ' )->once ()->with ([['key ' => 'prefixfoo ' , 'value ' => base64_encode (serialize ("\0" )), 'expiration ' => 61 ]], 'key ' )->andReturn (1 );
114
+
115
+ $ result = $ store ->put ('foo ' , "\0" , 60 );
116
+ $ this ->assertTrue ($ result );
117
+ }
118
+
95
119
public function testForeverCallsStoreItemWithReallyLongTime ()
96
120
{
97
121
$ store = $ this ->getMockBuilder (DatabaseStore::class)->onlyMethods (['put ' ])->setConstructorArgs ($ this ->getMocks ())->getMock ();
@@ -210,6 +234,11 @@ protected function getPostgresStore()
210
234
return new DatabaseStore (m::mock (PostgresConnection::class), 'table ' , 'prefix ' );
211
235
}
212
236
237
+ protected function getSqliteStore ()
238
+ {
239
+ return new DatabaseStore (m::mock (SQLiteConnection::class), 'table ' , 'prefix ' );
240
+ }
241
+
213
242
protected function getMocks ()
214
243
{
215
244
return [m::mock (Connection::class), 'table ' , 'prefix ' ];
@@ -219,4 +248,9 @@ protected function getPostgresMocks()
219
248
{
220
249
return [m::mock (PostgresConnection::class), 'table ' , 'prefix ' ];
221
250
}
251
+
252
+ protected function getSqliteMocks ()
253
+ {
254
+ return [m::mock (SQLiteConnection::class), 'table ' , 'prefix ' ];
255
+ }
222
256
}
0 commit comments