1
0
Fork 0

Add support for defining assertions on expected lock files to integration tests

pull/860/head
Nils Adermann 2012-07-01 18:27:16 +02:00
parent f0345f0592
commit 050439a0d3
1 changed files with 23 additions and 2 deletions

View File

@ -123,7 +123,7 @@ class InstallerTest extends TestCase
/** /**
* @dataProvider getIntegrationTests * @dataProvider getIntegrationTests
*/ */
public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expect) public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expectLock, $expect)
{ {
if ($condition) { if ($condition) {
eval('$res = '.$condition.';'); eval('$res = '.$condition.';');
@ -170,6 +170,17 @@ class InstallerTest extends TestCase
->method('exists') ->method('exists')
->will($this->returnValue(true)); ->will($this->returnValue(true));
if ($expectLock) {
$actualLock = array();
$lockJsonMock->expects($this->atLeastOnce())
->method('write')
->will($this->returnCallback(function ($hash, $options) use (&$actualLock) {
// need to do assertion outside of mock for nice phpunit output
// so store value temporarily in reference for later assetion
$actualLock = $hash;
}));
}
$locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig))); $locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig)));
$composer->setLocker($locker); $composer->setLocker($locker);
@ -208,6 +219,11 @@ class InstallerTest extends TestCase
fseek($appOutput, 0); fseek($appOutput, 0);
$this->assertEquals(0, $result, $output . stream_get_contents($appOutput)); $this->assertEquals(0, $result, $output . stream_get_contents($appOutput));
if ($expectLock) {
unset($actualLock['hash']);
$this->assertEquals($expectLock, $actualLock);
}
$installationManager = $composer->getInstallationManager(); $installationManager = $composer->getInstallationManager();
$this->assertSame($expect, implode("\n", $installationManager->getTrace())); $this->assertSame($expect, implode("\n", $installationManager->getTrace()));
} }
@ -233,12 +249,14 @@ class InstallerTest extends TestCase
(?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s* (?:--INSTALLED--\s*(?P<installed>'.$content.'))?\s*
(?:--INSTALLED:DEV--\s*(?P<installedDev>'.$content.'))?\s* (?:--INSTALLED:DEV--\s*(?P<installedDev>'.$content.'))?\s*
--RUN--\s*(?P<run>.*?)\s* --RUN--\s*(?P<run>.*?)\s*
(?:--EXPECT-LOCK--\s*(?P<expectLock>'.$content.'))?\s*
--EXPECT--\s*(?P<expect>.*?)\s* --EXPECT--\s*(?P<expect>.*?)\s*
$}xs'; $}xs';
$installed = array(); $installed = array();
$installedDev = array(); $installedDev = array();
$lock = array(); $lock = array();
$expectLock = array();
if (preg_match($pattern, $test, $match)) { if (preg_match($pattern, $test, $match)) {
try { try {
@ -258,6 +276,9 @@ class InstallerTest extends TestCase
$installedDev = JsonFile::parseJson($match['installedDev']); $installedDev = JsonFile::parseJson($match['installedDev']);
} }
$run = $match['run']; $run = $match['run'];
if (!empty($match['expectLock'])) {
$expectLock = JsonFile::parseJson($match['expectLock']);
}
$expect = $match['expect']; $expect = $match['expect'];
} catch (\Exception $e) { } catch (\Exception $e) {
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file))); die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file)));
@ -266,7 +287,7 @@ class InstallerTest extends TestCase
die(sprintf('Test "%s" is not valid, did not match the expected format.', str_replace($fixturesDir.'/', '', $file))); die(sprintf('Test "%s" is not valid, did not match the expected format.', str_replace($fixturesDir.'/', '', $file)));
} }
$tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expect); $tests[] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expectLock, $expect);
} }
return $tests; return $tests;