From b4c2347b2482d1e4e44dbccbabcdf1b1f5a85018 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 20 Feb 2013 16:50:26 +0100 Subject: [PATCH] Test fixes --- .../Test/Autoload/AutoloadGeneratorTest.php | 8 +-- tests/Composer/Test/Util/SvnTest.php | 49 ++++++++++++------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 77c47cab5..aceefa672 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -34,9 +34,9 @@ class AutoloadGeneratorTest extends TestCase $this->fs = new Filesystem; $that = $this; - $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest'; + $this->workingDir = realpath(sys_get_temp_dir()).DIRECTORY_SEPARATOR.'cmptest-'.md5(uniqid('', true)); $this->fs->ensureDirectoryExists($this->workingDir); - $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload-'.md5(uniqid('', true)); + $this->vendorDir = $this->workingDir.DIRECTORY_SEPARATOR.'composer-test-autoload'; $this->ensureDirectoryExistsAndClear($this->vendorDir); $this->config = $this->getMock('Composer\Config'); @@ -55,7 +55,7 @@ class AutoloadGeneratorTest extends TestCase return $that->vendorDir; })); - $this->dir = getcwd(); + $this->origDir = getcwd(); chdir($this->workingDir); $this->im = $this->getMockBuilder('Composer\Installer\InstallationManager') @@ -74,7 +74,7 @@ class AutoloadGeneratorTest extends TestCase protected function tearDown() { - chdir($this->dir); + chdir($this->origDir); if (is_dir($this->workingDir)) { $this->fs->removeDirectory($this->workingDir); diff --git a/tests/Composer/Test/Util/SvnTest.php b/tests/Composer/Test/Util/SvnTest.php index a29db7cee..fb938d72e 100644 --- a/tests/Composer/Test/Util/SvnTest.php +++ b/tests/Composer/Test/Util/SvnTest.php @@ -4,22 +4,8 @@ namespace Composer\Test\Util; use Composer\IO\NullIO; use Composer\Util\Svn; -class SvnTest +class SvnTest extends \PHPUnit_Framework_TestCase { - /** - * Provide some examples for {@self::testCredentials()}. - * - * @return array - */ - public function urlProvider() - { - return array( - array('http://till:test@svn.example.org/', $this->getCmd(" --no-auth-cache --username 'till' --password 'test' ")), - array('http://svn.apache.org/', ''), - array('svn://johndoe@example.org', $this->getCmd(" --no-auth-cache --username 'johndoe' --password '' ")), - ); - } - /** * Test the credential string. * @@ -31,8 +17,24 @@ class SvnTest public function testCredentials($url, $expect) { $svn = new Svn($url, new NullIO); + $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCredentialString'); + $reflMethod->setAccessible(true); + + $this->assertEquals($expect, $reflMethod->invoke($svn)); + } - $this->assertEquals($expect, $svn->getCredentialString()); + /** + * Provide some examples for {@self::testCredentials()}. + * + * @return array + */ + public function urlProvider() + { + return array( + array('http://till:test@svn.example.org/', $this->getCmd(" --username 'till' --password 'test' ")), + array('http://svn.apache.org/', ''), + array('svn://johndoe@example.org', $this->getCmd(" --username 'johndoe' --password '' ")), + ); } public function testInteractiveString() @@ -40,10 +42,21 @@ class SvnTest $url = 'http://svn.example.org'; $svn = new Svn($url, new NullIO()); + $reflMethod = new \ReflectionMethod('Composer\\Util\\Svn', 'getCommand'); + $reflMethod->setAccessible(true); $this->assertEquals( - "svn ls --non-interactive 'http://svn.example.org'", - $svn->getCommand('svn ls', $url) + $this->getCmd("svn ls --non-interactive 'http://svn.example.org'"), + $reflMethod->invokeArgs($svn, array('svn ls', $url)) ); } + + private function getCmd($cmd) + { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + return strtr($cmd, "'", '"'); + } + + return $cmd; + } }