Introduced more generic, less invasive way to test for exceptions in fixtures, more in line with how phpunit works.
parent
bd241cb896
commit
639ee0701c
|
@ -9,8 +9,8 @@ Tries to require a package with the same name as the root package
|
||||||
}
|
}
|
||||||
--RUN--
|
--RUN--
|
||||||
install
|
install
|
||||||
--EXPECT-OUTPUT--
|
--EXPECT-EXIT-CODE--
|
||||||
|
InvalidArgumentException
|
||||||
|
--EXPECT--
|
||||||
Root package 'foo/bar' cannot require itself in its composer.json
|
Root package 'foo/bar' cannot require itself in its composer.json
|
||||||
Did you accidentally name your root package after an external package?
|
Did you accidentally name your root package after an external package?
|
||||||
--EXPECT--
|
|
||||||
EXCEPTION
|
|
||||||
|
|
|
@ -159,7 +159,14 @@ class InstallerTest extends TestCase
|
||||||
->will($this->returnCallback($callback));
|
->will($this->returnCallback($callback));
|
||||||
|
|
||||||
// Prepare for exceptions
|
// 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);
|
$composer = FactoryMock::create($io, $composerConfig);
|
||||||
|
|
||||||
$jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
|
$jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock();
|
||||||
|
@ -235,8 +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);
|
||||||
$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) {
|
if ($expectLock) {
|
||||||
unset($actualLock['hash']);
|
unset($actualLock['hash']);
|
||||||
unset($actualLock['content-hash']);
|
unset($actualLock['content-hash']);
|
||||||
|
@ -251,17 +262,6 @@ class InstallerTest extends TestCase
|
||||||
$this->assertEquals(rtrim($expectOutput), rtrim($output));
|
$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()
|
public function getIntegrationTests()
|
||||||
{
|
{
|
||||||
|
@ -316,7 +316,7 @@ 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']) ? (int) $testData['EXPECT-EXIT-CODE'] : 0;
|
$expectExitCode = isset($testData['EXPECT-EXIT-CODE']) ? $testData['EXPECT-EXIT-CODE'] : 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)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue