Ver código fonte

[HttpKernel] added a return value to the purge() method of the Cache store class

Fabien Potencier 14 anos atrás
pai
commit
3506dfabff

+ 6 - 0
src/Symfony/Component/HttpKernel/Cache/Store.php

@@ -275,12 +275,18 @@ class Store
      * Purges data for the given URL.
      *
      * @param string $url A URL
+     *
+     * @return Boolean true if the URL exists and has been purged, false otherwise
      */
     public function purge($url)
     {
         if (file_exists($path = $this->getPath($this->getCacheKey(Request::create($url))))) {
             unlink($path);
+
+            return true;
         }
+
+        return false;
     }
 
     /**

+ 3 - 1
tests/Symfony/Tests/Component/HttpKernel/Cache/StoreTest.php

@@ -52,8 +52,10 @@ class CacheStoreTest extends \PHPUnit_Framework_TestCase
         $this->store->write($request, new Response('foo'));
         $this->assertNotEmpty($this->store->getMetadata($this->store->getCacheKey($request)));
 
-        $this->assertNull($this->store->purge('/foo'));
+        $this->assertTrue($this->store->purge('/foo'));
         $this->assertEmpty($this->store->getMetadata($this->store->getCacheKey($request)));
+
+        $this->assertFalse($this->store->purge('/bar'));
     }
 
     public function testStoresACacheEntry()