Browse Source

[DependencyInjection] fixed Resource interface

Fabien Potencier 15 năm trước cách đây
mục cha
commit
63e7dda4c8

+ 1 - 6
src/Symfony/Components/DependencyInjection/FileResource.php

@@ -49,18 +49,13 @@ class FileResource implements ResourceInterface
    *
    * @return Boolean true if the resource has not been updated, false otherwise
    */
-  public function isUptodate($timestamp = null)
+  public function isUptodate($timestamp)
   {
     if (!file_exists($this->resource))
     {
       return false;
     }
 
-    if (null === $timestamp)
-    {
-      $timestamp = time();
-    }
-
     return filemtime($this->resource) < $timestamp;
   }
 }

+ 1 - 1
src/Symfony/Components/DependencyInjection/ResourceInterface.php

@@ -27,7 +27,7 @@ interface ResourceInterface
    *
    * @return Boolean true if the resource has not been updated, false otherwise
    */
-  function isUptodate($timestamp = null);
+  function isUptodate($timestamp);
 
   /**
    * Returns the resource tied to this Resource.

+ 2 - 4
tests/unit/Symfony/Components/DependencyInjection/FileResourceTest.php

@@ -12,7 +12,7 @@ require_once __DIR__.'/../../../bootstrap.php';
 
 use Symfony\Components\DependencyInjection\FileResource;
 
-$t = new LimeTest(5);
+$t = new LimeTest(4);
 
 // ->getResource()
 $t->diag('->getResource()');
@@ -23,11 +23,9 @@ $t->is($resource->getResource(), $file, '->getResource() returns the path to the
 
 // ->isUptodate()
 $t->diag('->isUptodate()');
-sleep(1);
-$t->ok($resource->isUptodate(), '->isUptodate() returns true if the resource has not changed');
 $t->ok($resource->isUptodate(time() + 10), '->isUptodate() returns true if the resource has not changed');
 $t->ok(!$resource->isUptodate(time() - 86400), '->isUptodate() returns false if the resource has been updated');
 unlink($file);
 
 $resource = new FileResource('/____foo/foobar'.rand(1, 999999));
-$t->ok(!$resource->isUptodate(), '->isUptodate() returns false if the resource does not exist');
+$t->ok(!$resource->isUptodate(time()), '->isUptodate() returns false if the resource does not exist');