Parcourir la source

[Finder] Fixed tests on windows

Jordi Boggiano il y a 14 ans
Parent
commit
b3ae62e2c4

+ 3 - 3
tests/Symfony/Tests/Component/Finder/FinderTest.php

@@ -23,7 +23,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
     {
         parent::setUpBeforeClass();
 
-        self::$tmpDir = sys_get_temp_dir().'/symfony2_finder/';
+        self::$tmpDir = sys_get_temp_dir().'/symfony2_finder';
     }
 
     public function testDirectories()
@@ -186,7 +186,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
         $finder = new Finder();
         $iterator = $finder->files()->name('*.php')->depth('< 1')->in(array(self::$tmpDir, __DIR__))->getIterator();
 
-        $this->assertIterator(array(self::$tmpDir.'test.php', __DIR__.'/FinderTest.php', __DIR__.'/GlobTest.php'), $iterator);
+        $this->assertIterator(array(self::$tmpDir.DIRECTORY_SEPARATOR.'test.php', __DIR__.DIRECTORY_SEPARATOR.'FinderTest.php', __DIR__.DIRECTORY_SEPARATOR.'GlobTest.php'), $iterator);
     }
 
     public function testGetIterator()
@@ -226,7 +226,7 @@ class FinderTest extends Iterator\RealIteratorTestCase
     {
         $f = array();
         foreach ($files as $file) {
-            $f[] = self::$tmpDir.$file;
+            $f[] = self::$tmpDir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file);
         }
 
         return $f;

+ 10 - 5
tests/Symfony/Tests/Component/Finder/Iterator/DepthRangeIteratorTest.php

@@ -23,7 +23,7 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
      */
     public function testAccept($size, $expected)
     {
-        $inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(sys_get_temp_dir().'/symfony2_finder', \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
+        $inner = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getAbsolutePath(''), \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
 
         $iterator = new DepthRangeFilterIterator($inner, $size);
 
@@ -36,11 +36,16 @@ class DepthRangeFilterIteratorTest extends RealIteratorTestCase
     public function getAcceptData()
     {
         return array(
-            array(array(new NumberComparator('< 1')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto')),
-            array(array(new NumberComparator('<= 1')), array(sys_get_temp_dir().'/symfony2_finder/.git', sys_get_temp_dir().'/symfony2_finder/test.py', sys_get_temp_dir().'/symfony2_finder/foo', sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', sys_get_temp_dir().'/symfony2_finder/test.php', sys_get_temp_dir().'/symfony2_finder/toto')),
+            array(array(new NumberComparator('< 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'))),
+            array(array(new NumberComparator('<= 1')), array($this->getAbsolutePath('/.git'), $this->getAbsolutePath('/test.py'), $this->getAbsolutePath('/foo'), $this->getAbsolutePath('/foo/bar.tmp'), $this->getAbsolutePath('/test.php'), $this->getAbsolutePath('/toto'))),
             array(array(new NumberComparator('> 1')), array()),
-            array(array(new NumberComparator('>= 1')), array(sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp')),
-            array(array(new NumberComparator('1')), array(sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp')),
+            array(array(new NumberComparator('>= 1')), array($this->getAbsolutePath('/foo/bar.tmp'))),
+            array(array(new NumberComparator('1')), array($this->getAbsolutePath('/foo/bar.tmp'))),
         );
     }
+
+    protected function getAbsolutePath($path)
+    {
+        return sys_get_temp_dir().'/symfony2_finder'.str_replace('/', DIRECTORY_SEPARATOR, $path);
+    }
 }

+ 10 - 10
tests/Symfony/Tests/Component/Finder/Iterator/ExcludeDirectoryFileIteratorTest.php

@@ -35,18 +35,18 @@ class ExcludeDirectoryFilterIteratorTest extends RealIteratorTestCase
 
         return array(
             array(array('foo'), array(
-                $tmpDir.'/.git',
-                $tmpDir.'/test.py',
-                $tmpDir.'/test.php',
-                $tmpDir.'/toto'
+                $tmpDir.DIRECTORY_SEPARATOR.'.git',
+                $tmpDir.DIRECTORY_SEPARATOR.'test.py',
+                $tmpDir.DIRECTORY_SEPARATOR.'test.php',
+                $tmpDir.DIRECTORY_SEPARATOR.'toto'
             )),
             array(array('fo'), array(
-                $tmpDir.'/.git',
-                $tmpDir.'/test.py',
-                $tmpDir.'/foo',
-                $tmpDir.'/foo/bar.tmp',
-                $tmpDir.'/test.php',
-                $tmpDir.'/toto'
+                $tmpDir.DIRECTORY_SEPARATOR.'.git',
+                $tmpDir.DIRECTORY_SEPARATOR.'test.py',
+                $tmpDir.DIRECTORY_SEPARATOR.'foo',
+                $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
+                $tmpDir.DIRECTORY_SEPARATOR.'test.php',
+                $tmpDir.DIRECTORY_SEPARATOR.'toto'
             )),
         );
     }

+ 5 - 5
tests/Symfony/Tests/Component/Finder/Iterator/IgnoreVcsFilterIteratorTest.php

@@ -26,11 +26,11 @@ class IgnoreVcsFilterIteratorTest extends RealIteratorTestCase
         $tmpDir = sys_get_temp_dir().'/symfony2_finder';
 
         $this->assertIterator(array(
-            $tmpDir.'/test.py',
-            $tmpDir.'/foo',
-            $tmpDir.'/foo/bar.tmp',
-            $tmpDir.'/test.php',
-            $tmpDir.'/toto'
+            $tmpDir.DIRECTORY_SEPARATOR.'test.py',
+            $tmpDir.DIRECTORY_SEPARATOR.'foo',
+            $tmpDir.DIRECTORY_SEPARATOR.'foo'.DIRECTORY_SEPARATOR.'bar.tmp',
+            $tmpDir.DIRECTORY_SEPARATOR.'test.php',
+            $tmpDir.DIRECTORY_SEPARATOR.'toto'
         ), $iterator);
     }
 }

+ 4 - 4
tests/Symfony/Tests/Component/Finder/Iterator/RealIteratorTestCase.php

@@ -31,9 +31,9 @@ class RealIteratorTestCase extends IteratorTestCase
 
         if (is_dir($tmpDir)) {
             self::tearDownAfterClass();
-            rmdir($tmpDir);
+        } else {
+            mkdir($tmpDir);
         }
-        mkdir($tmpDir);
 
         foreach (self::$files as $file) {
             if ('/' === $file[strlen($file) - 1]) {
@@ -46,8 +46,8 @@ class RealIteratorTestCase extends IteratorTestCase
         file_put_contents($tmpDir.'/test.php', str_repeat(' ', 800));
         file_put_contents($tmpDir.'/test.py', str_repeat(' ', 2000));
 
-        touch(sys_get_temp_dir().'/symfony2_finder/foo/bar.tmp', strtotime('2005-10-15'));
-        touch(sys_get_temp_dir().'/symfony2_finder/test.php', strtotime('2005-10-15'));
+        touch($tmpDir.'/foo/bar.tmp', strtotime('2005-10-15'));
+        touch($tmpDir.'/test.php', strtotime('2005-10-15'));
     }
 
     static public function tearDownAfterClass()