Add check to Store::unlock to ensure file exists
Fix indentation and shorten code
This commit is contained in:
parent
462f93ad12
commit
a094f7e2a5
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user