Cleaner notation for expected exceptions in fixtures.
parent
639ee0701c
commit
523362c7c5
|
@ -9,7 +9,7 @@ Tries to require a package with the same name as the root package
|
||||||
}
|
}
|
||||||
--RUN--
|
--RUN--
|
||||||
install
|
install
|
||||||
--EXPECT-EXIT-CODE--
|
--EXPECT-EXCEPTION--
|
||||||
InvalidArgumentException
|
InvalidArgumentException
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Root package 'foo/bar' cannot require itself in its composer.json
|
Root package 'foo/bar' cannot require itself in its composer.json
|
||||||
|
|
|
@ -137,7 +137,7 @@ class InstallerTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider getIntegrationTests
|
* @dataProvider getIntegrationTests
|
||||||
*/
|
*/
|
||||||
public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectExitCode)
|
public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectResult)
|
||||||
{
|
{
|
||||||
if ($condition) {
|
if ($condition) {
|
||||||
eval('$res = '.$condition.';');
|
eval('$res = '.$condition.';');
|
||||||
|
@ -159,11 +159,11 @@ class InstallerTest extends TestCase
|
||||||
->will($this->returnCallback($callback));
|
->will($this->returnCallback($callback));
|
||||||
|
|
||||||
// Prepare for exceptions
|
// Prepare for exceptions
|
||||||
if (is_int($expectExitCode) || ctype_digit($expectExitCode)) {
|
if (is_int($expectResult) || ctype_digit($expectResult)) {
|
||||||
$expectExitCode = (int) $expectExitCode;
|
$expectResult = (int) $expectResult;
|
||||||
} else {
|
} else {
|
||||||
$normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect));
|
$normalizedOutput = rtrim(str_replace("\n", PHP_EOL, $expect));
|
||||||
$this->setExpectedException($expectExitCode, $normalizedOutput);
|
$this->setExpectedException($expectResult, $normalizedOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Composer mock object according to configuration
|
// Create Composer mock object according to configuration
|
||||||
|
@ -242,12 +242,12 @@ class InstallerTest extends TestCase
|
||||||
$appOutput = fopen('php://memory', 'w+');
|
$appOutput = fopen('php://memory', 'w+');
|
||||||
$result = $application->run(new StringInput($run), new StreamOutput($appOutput));
|
$result = $application->run(new StringInput($run), new StreamOutput($appOutput));
|
||||||
fseek($appOutput, 0);
|
fseek($appOutput, 0);
|
||||||
if (!is_int($expectExitCode)) {
|
if (!is_int($expectResult)) {
|
||||||
// Shouldn't check output and results if an exception was expected by this point
|
// Shouldn't check output and results if an exception was expected by this point
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expectExitCode, $result, $output . stream_get_contents($appOutput));
|
$this->assertEquals($expectResult, $result, $output . stream_get_contents($appOutput));
|
||||||
if ($expectLock) {
|
if ($expectLock) {
|
||||||
unset($actualLock['hash']);
|
unset($actualLock['hash']);
|
||||||
unset($actualLock['content-hash']);
|
unset($actualLock['content-hash']);
|
||||||
|
@ -279,7 +279,7 @@ class InstallerTest extends TestCase
|
||||||
$installedDev = array();
|
$installedDev = array();
|
||||||
$lock = array();
|
$lock = array();
|
||||||
$expectLock = array();
|
$expectLock = array();
|
||||||
$expectExitCode = 0;
|
$expectResult = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$message = $testData['TEST'];
|
$message = $testData['TEST'];
|
||||||
|
@ -316,12 +316,21 @@ class InstallerTest extends TestCase
|
||||||
}
|
}
|
||||||
$expectOutput = isset($testData['EXPECT-OUTPUT']) ? $testData['EXPECT-OUTPUT'] : null;
|
$expectOutput = isset($testData['EXPECT-OUTPUT']) ? $testData['EXPECT-OUTPUT'] : null;
|
||||||
$expect = $testData['EXPECT'];
|
$expect = $testData['EXPECT'];
|
||||||
$expectExitCode = isset($testData['EXPECT-EXIT-CODE']) ? $testData['EXPECT-EXIT-CODE'] : 0;
|
if (!empty($testData['EXPECT-EXCEPTION'])) {
|
||||||
|
$expectResult = $testData['EXPECT-EXCEPTION'];
|
||||||
|
if (!empty($testData['EXPECT-EXIT-CODE'])) {
|
||||||
|
throw new \LogicException('EXPECT-EXCEPTION and EXPECT-EXIT-CODE are mutually exclusive');
|
||||||
|
}
|
||||||
|
} elseif (!empty($testData['EXPECT-EXIT-CODE'])) {
|
||||||
|
$expectResult = (int) $testData['EXPECT-EXIT-CODE'];
|
||||||
|
} else {
|
||||||
|
$expectResult = 0;
|
||||||
|
}
|
||||||
} 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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tests[basename($file)] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectExitCode);
|
$tests[basename($file)] = array(str_replace($fixturesDir.'/', '', $file), $message, $condition, $composer, $lock, $installed, $run, $expectLock, $expectOutput, $expect, $expectResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tests;
|
return $tests;
|
||||||
|
@ -341,6 +350,7 @@ class InstallerTest extends TestCase
|
||||||
'EXPECT-LOCK' => false,
|
'EXPECT-LOCK' => false,
|
||||||
'EXPECT-OUTPUT' => false,
|
'EXPECT-OUTPUT' => false,
|
||||||
'EXPECT-EXIT-CODE' => false,
|
'EXPECT-EXIT-CODE' => false,
|
||||||
|
'EXPECT-EXCEPTION' => false,
|
||||||
'EXPECT' => true,
|
'EXPECT' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue