diff -u b/core/lib/Drupal/Component/PhpStorage/FileStorage.php b/core/lib/Drupal/Component/PhpStorage/FileStorage.php --- b/core/lib/Drupal/Component/PhpStorage/FileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php @@ -37,7 +37,8 @@ * Implements Drupal\Component\PhpStorage\PhpStorageInterface::exists(). */ public function exists($name) { - return file_exists($this->getFullPath($name)); + $path = $this->getFullPath($name); + return file_exists($path); } /** @@ -45,11 +46,7 @@ */ public function load($name) { $path = $this->getFullPath($name); - if (file_exists($path)) { - include_once($path); - return TRUE; - } - return FALSE; + @include_once($path); } /** @@ -65,7 +62,8 @@ * Implements Drupal\Component\PhpStorage\PhpStorageInterface::delete(). */ public function delete($name) { - return @unlink($this->getFullPath($name)); + $path = $this->getFullPath($name); + return @unlink($path); } /** diff -u b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php --- b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php +++ b/core/lib/Drupal/Component/PhpStorage/PhpStorageInterface.php @@ -32,11 +32,14 @@ /** * Loads PHP code from storage. * + * Depending on storage implementation, exists() checks can be expensive, so + * this function may be called for a file that doesn't exist, and that should + * not result in errors. This function does not return anything, so it is + * up to the caller to determine if any code was loaded (for example, check + * class_exists() or function_exists() for what was expected in the code). + * * @param string $name * The virtual file name. Can be a relative path. - * - * @return bool - * TRUE if the load succeeded, FALSE if it failed. */ public function load($name); diff -u b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php --- b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -948,7 +948,5 @@ */ public static function filePreDeleteCallback($path) { - if (file_exists($path)) { - chmod($path, 0700); - } + chmod($path, 0700); } } diff -u b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php --- b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/FileStorageTest.php @@ -31,10 +31,10 @@ /** - * Tests the FileStorage implementation. + * Tests basic load/save/delete operations. */ - function testFileStorage() { + function testCRUD() { $php = drupal_php_storage('simpletest'); $this->assertIdentical(get_class($php), 'Drupal\Component\PhpStorage\FileStorage'); - $this->doTest($php); + $this->assertCRUD($php); } } diff -u b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php --- b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php @@ -31,12 +31,12 @@ } /** - * Tests the MTimeProtectedFileStorage implementation. + * Tests basic load/save/delete operations. */ - function testMTimeProtectedFileStorage() { + function testCRUD() { $php = drupal_php_storage('simpletest'); $this->assertIdentical(get_class($php), 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'); - $this->doTest($php); + $this->assertCRUD($php); } /** @@ -80,8 +80,7 @@ chmod($expected_filename, 0400); chmod($expected_directory, 0100); $this->assertIdentical(file_get_contents($expected_filename), $untrusted_code); - $success = $php->load($name); - $this->assertIdentical($success, FALSE); + $php->load($name); $this->assertIdentical($hacked, FALSE); $this->assertIdentical($php->exists($name), FALSE); } diff -u b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/PhpStorageTestBase.php b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/PhpStorageTestBase.php --- b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/PhpStorageTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/PhpStorage/PhpStorageTestBase.php @@ -10,14 +10,14 @@ use Drupal\simpletest\UnitTestBase; /** - * Base test for PHP loaders. + * Base test for PHP storage controllers. */ abstract class PhpStorageTestBase extends UnitTestBase { /** - * Test a PHP code storage controller. + * Assert that a PHP storage controller's load/save/delete operations work. */ - public function doTest($php) { + public function assertCRUD($php) { $name = $this->randomName() . '/' . $this->randomName() . '.php'; // Find a function name that doesn't exist. @@ -30,19 +30,17 @@ $code = "save($name, $code); $this->assertIdentical($success, TRUE); - $success = $php->load($name); - $this->assertIdentical($success, TRUE); + $php->load($name); $this->assertIdentical($function(), $random); // If the file was successfully loaded, it must also exist, but ensure the // exists() method returns that correctly. $this->assertIdentical($php->exists($name), TRUE); - // Delete the file, and then ensure exists() and load() return FALSE. + // Delete the file, and then ensure exists() returns FALSE. $success = $php->delete($name); $this->assertIdentical($success, TRUE); $this->assertIdentical($php->exists($name), FALSE); - $this->assertIdentical($php->load($name), FALSE); // Ensure delete() can be called on a non-existing file. It should return // FALSE, but not trigger errors.