Fix Windows escaping in tests
parent
8f974fe741
commit
0783b043d2
|
@ -15,7 +15,6 @@ namespace Composer\Test\Downloader;
|
|||
use Composer\Downloader\FossilDownloader;
|
||||
use Composer\Test\TestCase;
|
||||
use Composer\Util\Filesystem;
|
||||
use Composer\Util\Platform;
|
||||
|
||||
class FossilDownloaderTest extends TestCase
|
||||
{
|
||||
|
@ -168,9 +167,4 @@ class FossilDownloaderTest extends TestCase
|
|||
|
||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||
}
|
||||
|
||||
private function getCmd($cmd)
|
||||
{
|
||||
return Platform::isWindows() ? strtr($cmd, "'", '"') : $cmd;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -701,7 +701,7 @@ composer https://github.com/old/url (push)
|
|||
$cmd = str_replace('cd ', 'cd /D ', $cmd);
|
||||
$cmd = str_replace('composerPath', getcwd().'/composerPath', $cmd);
|
||||
|
||||
return strtr($cmd, "'", '"');
|
||||
return $this->getCmd($cmd);
|
||||
}
|
||||
|
||||
return $cmd;
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace Composer\Test\Downloader;
|
|||
use Composer\Downloader\HgDownloader;
|
||||
use Composer\Test\TestCase;
|
||||
use Composer\Util\Filesystem;
|
||||
use Composer\Util\Platform;
|
||||
|
||||
class HgDownloaderTest extends TestCase
|
||||
{
|
||||
|
@ -157,9 +156,4 @@ class HgDownloaderTest extends TestCase
|
|||
|
||||
$this->assertEquals('source', $downloader->getInstallationSource());
|
||||
}
|
||||
|
||||
private function getCmd($cmd)
|
||||
{
|
||||
return Platform::isWindows() ? strtr($cmd, "'", '"') : $cmd;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -401,7 +401,7 @@ class EventDispatcherTest extends TestCase
|
|||
|
||||
$dispatcher->dispatch('helloWorld', new CommandEvent('helloWorld', $composer, $io));
|
||||
$expected = "> helloWorld: @hello World".PHP_EOL.
|
||||
"> hello: echo Hello " .escapeshellarg('World').PHP_EOL;
|
||||
"> hello: echo Hello " .$this->getCmd("'World'").PHP_EOL;
|
||||
|
||||
$this->assertEquals($expected, $io->getOutput());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use Composer\Semver\VersionParser;
|
|||
use Composer\Package\AliasPackage;
|
||||
use Composer\Semver\Constraint\Constraint;
|
||||
use Composer\Util\Filesystem;
|
||||
use Composer\Util\Platform;
|
||||
use Composer\Util\Silencer;
|
||||
use PHPUnit\Framework\TestCase as BaseTestCase;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
@ -125,4 +126,24 @@ abstract class TestCase extends BaseTestCase
|
|||
parent::setExpectedException($exception, $message, $code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an escaped non-Windows command to match Windows escaping.
|
||||
*
|
||||
* @param string $cmd
|
||||
*
|
||||
* @return string The transformed command
|
||||
*/
|
||||
protected function getCmd($cmd)
|
||||
{
|
||||
if (Platform::isWindows()) {
|
||||
$cmd = preg_replace_callback("/('[^']*')/", function ($m) {
|
||||
// Double-quotes are used only when needed
|
||||
$char = (strpbrk($m[1], " \t^&|<>()") !== false || $m[1] === "''") ? '"' : '';
|
||||
return str_replace("'", $char, $m[1]);
|
||||
}, $cmd);
|
||||
}
|
||||
|
||||
return $cmd;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ namespace Composer\Test\Util;
|
|||
|
||||
use Composer\Config;
|
||||
use Composer\IO\NullIO;
|
||||
use Composer\Util\Platform;
|
||||
use Composer\Util\Svn;
|
||||
use Composer\Test\TestCase;
|
||||
|
||||
|
@ -130,9 +129,4 @@ class SvnTest extends TestCase
|
|||
|
||||
$this->assertEquals($this->getCmd(" --no-auth-cache --username 'foo' --password 'bar' "), $reflMethod->invoke($svn));
|
||||
}
|
||||
|
||||
private function getCmd($cmd)
|
||||
{
|
||||
return Platform::isWindows() ? strtr($cmd, "'", '"') : $cmd;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue