|
3 | 3 | namespace Illuminate\Tests\Cache; |
4 | 4 |
|
5 | 5 | use Closure; |
6 | | -use Exception; |
7 | 6 | use Illuminate\Cache\DatabaseStore; |
8 | 7 | use Illuminate\Database\Connection; |
9 | 8 | use Illuminate\Database\PostgresConnection; |
@@ -63,41 +62,25 @@ public function testValueIsReturnedOnPostgres() |
63 | 62 | $this->assertSame('bar', $store->get('foo')); |
64 | 63 | } |
65 | 64 |
|
66 | | - public function testValueIsInsertedWhenNoExceptionsAreThrown() |
| 65 | + public function testValueIsUpserted() |
67 | 66 | { |
68 | 67 | $store = $this->getMockBuilder(DatabaseStore::class)->onlyMethods(['getTime'])->setConstructorArgs($this->getMocks())->getMock(); |
69 | 68 | $table = m::mock(stdClass::class); |
70 | 69 | $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); |
71 | 70 | $store->expects($this->once())->method('getTime')->willReturn(1); |
72 | | - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnTrue(); |
| 71 | + $table->shouldReceive('upsert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61], 'key')->andReturnTrue(); |
73 | 72 |
|
74 | 73 | $result = $store->put('foo', 'bar', 60); |
75 | 74 | $this->assertTrue($result); |
76 | 75 | } |
77 | 76 |
|
78 | | - public function testValueIsUpdatedWhenInsertThrowsException() |
79 | | - { |
80 | | - $store = $this->getMockBuilder(DatabaseStore::class)->onlyMethods(['getTime'])->setConstructorArgs($this->getMocks())->getMock(); |
81 | | - $table = m::mock(stdClass::class); |
82 | | - $store->getConnection()->shouldReceive('table')->with('table')->andReturn($table); |
83 | | - $store->expects($this->once())->method('getTime')->willReturn(1); |
84 | | - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnUsing(function () { |
85 | | - throw new Exception; |
86 | | - }); |
87 | | - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); |
88 | | - $table->shouldReceive('update')->once()->with(['value' => serialize('bar'), 'expiration' => 61])->andReturnTrue(); |
89 | | - |
90 | | - $result = $store->put('foo', 'bar', 60); |
91 | | - $this->assertTrue($result); |
92 | | - } |
93 | | - |
94 | | - public function testValueIsInsertedOnPostgres() |
| 77 | + public function testValueIsUpsertedOnPostgres() |
95 | 78 | { |
96 | 79 | $store = $this->getMockBuilder(DatabaseStore::class)->onlyMethods(['getTime'])->setConstructorArgs($this->getPostgresMocks())->getMock(); |
97 | 80 | $table = m::mock(stdClass::class); |
98 | 81 | $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); |
99 | 82 | $store->expects($this->once())->method('getTime')->willReturn(1); |
100 | | - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => base64_encode(serialize("\0")), 'expiration' => 61])->andReturnTrue(); |
| 83 | + $table->shouldReceive('upsert')->once()->with(['key' => 'prefixfoo', 'value' => base64_encode(serialize("\0")), 'expiration' => 61], 'key')->andReturn(1); |
101 | 84 |
|
102 | 85 | $result = $store->put('foo', "\0", 60); |
103 | 86 | $this->assertTrue($result); |
|
0 commit comments