Parcourir la source

Fix test & behavior

Jordi Boggiano il y a 13 ans
Parent
commit
edf93f1fcc

+ 6 - 4
src/Composer/Util/Filesystem.php

@@ -66,11 +66,12 @@ class Filesystem
             throw new \InvalidArgumentException('from and to must be absolute paths');
         }
 
+        $from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
+        $to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
+
         if (dirname($from) === dirname($to)) {
             return './'.basename($to);
         }
-        $from = lcfirst(rtrim(strtr($from, '\\', '/'), '/'));
-        $to = lcfirst(rtrim(strtr($to, '\\', '/'), '/'));
 
         $commonPath = $to;
         while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
@@ -101,11 +102,12 @@ class Filesystem
             throw new \InvalidArgumentException('from and to must be absolute paths');
         }
 
+        $from = lcfirst(strtr($from, '\\', '/'));
+        $to = lcfirst(strtr($to, '\\', '/'));
+
         if ($from === $to) {
             return $directories ? '__DIR__' : '__FILE__';
         }
-        $from = lcfirst(strtr($from, '\\', '/'));
-        $to = lcfirst(strtr($to, '\\', '/'));
 
         $commonPath = $to;
         while (strpos($from, $commonPath) !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {

+ 3 - 3
tests/Composer/Test/Autoload/Fixtures/autoload_main3.php

@@ -3,9 +3,9 @@
 // autoload_namespace.php generated by Composer
 
 $vendorDir = dirname(__DIR__);
-$baseDir = dirname($vendorDir);
+$baseDir = $vendorDir;
 
 return array(
-    'Main' => $vendorDir . '/src/',
-    'Lala' => $vendorDir . '/src/',
+    'Main' => $baseDir . '/src/',
+    'Lala' => $baseDir . '/src/',
 );

+ 2 - 0
tests/Composer/Test/Util/FilesystemTest.php

@@ -41,6 +41,8 @@ class FilesystemTest extends TestCase
             array('/foo/bar', '/foo/baz', true, "dirname(__DIR__).'/baz'"),
             array('/foo/bin/run', '/foo/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"),
             array('/foo/bin/run', '/bar/bin/run', true, "'/bar/bin/run'"),
+            array('/bin/run', '/bin/run', true, "__DIR__"),
+            array('c:/bin/run', 'c:\\bin/run', true, "__DIR__"),
             array('c:/bin/run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"),
             array('c:\\bin\\run', 'c:/vendor/acme/bin/run', true, "dirname(dirname(__DIR__)).'/vendor/acme/bin/run'"),
             array('c:/bin/run', 'd:/vendor/acme/bin/run', true, "'d:/vendor/acme/bin/run'"),