diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index e5445753a1..88f43b9e3f 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -86,10 +86,14 @@ class Store implements StoreInterface * Releases the lock for the given Request. * * @param Request $request A Request instance + * + * @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise */ public function unlock(Request $request) { - return @unlink($this->getPath($this->getCacheKey($request).'.lck')); + $file = $this->getPath($this->getCacheKey($request).'.lck'); + + return is_file($file) ? @unlink($file) : false; } /** diff --git a/src/Symfony/Component/HttpKernel/HttpCache/StoreInterface.php b/src/Symfony/Component/HttpKernel/HttpCache/StoreInterface.php index dd8c886979..9284170462 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/StoreInterface.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/StoreInterface.php @@ -66,6 +66,8 @@ interface StoreInterface * Releases the lock for the given Request. * * @param Request $request A Request instance + * + * @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise */ public function unlock(Request $request); diff --git a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/StoreTest.php b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/StoreTest.php index 4e266af04a..27c6272c53 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/HttpCache/StoreTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/HttpCache/StoreTest.php @@ -19,8 +19,19 @@ use Symfony\Component\HttpKernel\HttpCache\Store; class StoreTest extends \PHPUnit_Framework_TestCase { + /** + * @var Request + */ protected $request; + + /** + * @var Response + */ protected $response; + + /** + * @var Store + */ protected $store; protected function setUp() @@ -47,6 +58,19 @@ class StoreTest extends \PHPUnit_Framework_TestCase $this->assertEmpty($this->getStoreMetadata('/nothing')); } + public function testUnlockFileThatDoesExist() + { + $cacheKey = $this->storeSimpleEntry(); + $this->store->lock($this->request); + + $this->assertTrue($this->store->unlock($this->request)); + } + + public function testUnlockFileThatDoesNotExist() + { + $this->assertFalse($this->store->unlock($this->request)); + } + public function testRemovesEntriesForKeyWithPurge() { $request = Request::create('/foo');