diff --git a/lib/Doctrine/ORM/Cache/Region/FileLockRegion.php b/lib/Doctrine/ORM/Cache/Region/FileLockRegion.php index 7e20d5f73..083329c55 100644 --- a/lib/Doctrine/ORM/Cache/Region/FileLockRegion.php +++ b/lib/Doctrine/ORM/Cache/Region/FileLockRegion.php @@ -201,8 +201,14 @@ class FileLockRegion implements ConcurrentRegion */ public function evictAll() { - foreach (glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION)) as $filename) { - @unlink($filename); + // The check below is necessary because on some platforms glob returns false + // when nothing matched (even though no errors occurred) + $filenames = glob(sprintf("%s/*.%s" , $this->directory, self::LOCK_EXTENSION)); + + if ($filenames) { + foreach ($filenames as $filename) { + @unlink($filename); + } } return $this->region->evictAll(); diff --git a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php index e699bb39f..6fdef6fea 100644 --- a/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/FileLockRegionTest.php @@ -27,17 +27,12 @@ class FileLockRegionTest extends AbstractRegionTest */ protected $directory; + /** + * {@inheritDoc} + */ public function tearDown() { - if ( ! is_dir($this->directory)) { - return; - } - - foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->directory), RecursiveIteratorIterator::CHILD_FIRST) as $file) { - $file->isFile() - ? @unlink($file->getRealPath()) - : @rmdir($file->getRealPath()); - } + $this->cleanTestDirectory($this->directory); } /** @@ -247,4 +242,46 @@ class FileLockRegionTest extends AbstractRegionTest $this->assertNotNull($this->region->get($key)); $this->assertFileNotExists($file); } -} \ No newline at end of file + + /** + * @group 1072 + * @group DDC-3191 + */ + public function testHandlesScanErrorsGracefullyOnEvictAll() + { + $region = $this->createRegion(); + $reflectionDirectory = new \ReflectionProperty($region, 'directory'); + + $reflectionDirectory->setAccessible(true); + $reflectionDirectory->setValue($region, str_repeat('a', 10000)); + + set_error_handler(function () {}, E_WARNING); + $this->assertTrue($region->evictAll()); + restore_error_handler(); + } + + /** + * @param string|null $path directory to clean + */ + private function cleanTestDirectory($path) + { + $path = $path ?: $this->directory; + + if ( ! is_dir($path)) { + return; + } + + $directoryIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path), + RecursiveIteratorIterator::CHILD_FIRST + ); + + foreach ($directoryIterator as $file) { + if ($file->isFile()) { + @unlink($file->getRealPath()); + } else { + @rmdir($file->getRealPath()); + } + } + } +} diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 3ad2c88f1..7c3c33c6a 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -393,8 +393,10 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest return unlink($path); } else if (is_dir($path)) { $files = glob(rtrim($path,'/').'/*'); - foreach ($files as $file){ - $this->_deleteDirectory($file); + if (is_array($files)) { + foreach ($files as $file){ + $this->_deleteDirectory($file); + } } return rmdir($path); }