diff --git a/tests/Integration/Database/DatabaseCacheStoreTest.php b/tests/Integration/Database/DatabaseCacheStoreTest.php index 1f5bac9835d0..86264fb81891 100644 --- a/tests/Integration/Database/DatabaseCacheStoreTest.php +++ b/tests/Integration/Database/DatabaseCacheStoreTest.php @@ -41,6 +41,66 @@ public function testValueCanUpdateExistCacheInTransaction() $this->assertSame('new-bar', $store->get('foo')); } + public function testAddOperationCanStoreNewCache() + { + $store = $this->getStore(); + + $result = $store->add('foo', 'bar', 60); + + $this->assertTrue($result); + $this->assertSame('bar', $store->get('foo')); + } + + public function testAddOperationShouldNotUpdateExistCache() + { + $store = $this->getStore(); + + $store->add('foo', 'bar', 60); + $result = $store->add('foo', 'new-bar', 60); + + $this->assertFalse($result); + $this->assertSame('bar', $store->get('foo')); + } + + public function testAddOperationShouldNotUpdateExistCacheInTransaction() + { + $store = $this->getStore(); + + $store->add('foo', 'bar', 60); + + DB::beginTransaction(); + $result = $store->add('foo', 'new-bar', 60); + DB::commit(); + + $this->assertFalse($result); + $this->assertSame('bar', $store->get('foo')); + } + + public function testAddOperationCanUpdateIfCacheExpired() + { + $store = $this->getStore(); + + $store->add('foo', 'bar', 0); + $result = $store->add('foo', 'new-bar', 60); + + $this->assertTrue($result); + $this->assertSame('new-bar', $store->get('foo')); + } + + public function testAddOperationCanUpdateIfCacheExpiredInTransaction() + { + $store = $this->getStore(); + + $store->add('foo', 'bar', 0); + + DB::beginTransaction(); + $result = $store->add('foo', 'new-bar', 60); + DB::commit(); + + $this->assertTrue($result); + $this->assertSame('new-bar', $store->get('foo')); + } + protected function getStore() { return Cache::store('database');