1
0
Fork 0

Introduced more generic, less invasive way to test for exceptions in fixtures, more in line with how phpunit works.

pull/4838/head
Niels Keurentjes 2016-01-27 13:19:08 +01:00
parent bd241cb896
commit 639ee0701c
2 changed files with 104 additions and 104 deletions

View File

@ -9,8 +9,8 @@ Tries to require a package with the same name as the root package
}
--RUN--
install
--EXPECT-OUTPUT--
--EXPECT-EXIT-CODE--
InvalidArgumentException
--EXPECT--
Root package 'foo/bar' cannot require itself in its composer.json
Did you accidentally name your root package after an external package?
--EXPECT--
EXCEPTION

View File

@ -159,7 +159,14 @@ class InstallerTest extends TestCase
->will($this->returnCallback($callback));
// Prepare for exceptions
try {
if (is_int($expectExitCode) || ctype_digit($expectExitCode)) {
$expectExitCode = (int) $expectExitCode;
} else {
$normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect));
$this->setExpectedException($expectExitCode, $normalizedOutput);
}
// Create Composer mock object according to configuration
$composer = FactoryMock::create($io, $composerConfig);
$jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
@ -235,8 +242,12 @@ class InstallerTest extends TestCase
$appOutput = fopen('php://memory', 'w+');
$result = $application->run(new StringInput($run), new StreamOutput($appOutput));
fseek($appOutput, 0);
$this->assertEquals($expectExitCode, $result, $output . stream_get_contents($appOutput));
if (!is_int($expectExitCode)) {
// Shouldn't check output and results if an exception was expected by this point
return;
}
$this->assertEquals($expectExitCode, $result, $output . stream_get_contents($appOutput));
if ($expectLock) {
unset($actualLock['hash']);
unset($actualLock['content-hash']);
@ -251,17 +262,6 @@ class InstallerTest extends TestCase
$this->assertEquals(rtrim($expectOutput), rtrim($output));
}
}
catch(\Exception $e) {
// Exception was thrown during execution
if (!$expect || !$expectOutput) {
throw $e;
}
$this->assertEquals('EXCEPTION', rtrim($expect));
$normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expectOutput));
$this->assertEquals($normalizedOutput, rtrim($e->getMessage()));
}
return;
}
public function getIntegrationTests()
{
@ -316,7 +316,7 @@ class InstallerTest extends TestCase
}
$expectOutput = isset($testData['EXPECT-OUTPUT']) ? $testData['EXPECT-OUTPUT'] : null;
$expect = $testData['EXPECT'];
$expectExitCode = isset($testData['EXPECT-EXIT-CODE']) ? (int) $testData['EXPECT-EXIT-CODE'] : 0;
$expectExitCode = isset($testData['EXPECT-EXIT-CODE']) ? $testData['EXPECT-EXIT-CODE'] : 0;
} catch (\Exception $e) {
die(sprintf('Test "%s" is not valid: '.$e->getMessage(), str_replace($fixturesDir.'/', '', $file)));
}