Hi I am using PHPUnit for my unit testing
I have a problem regarding testing output using the expectOutputString/expectOutputRegex method
Problem :
function test_myTest() {
$this->expectOutputString('testxzxzxzxzxz');
$this->expectOutputString('test');
echo 'test';
}
This test pass when i generate unit test report even though the first expectation fails
Unlike in the assert methods, test fail if there is one assertion that fails
Example assertTrue :
// this test fail because the first assertTrue fails
function test_myAssert() {
$this->assertTrue(false);
$this->assertTrue(true);
}
Looks like this is a lacking functionality in PHPUnit..
Anyone have ideas or alternative way to achieve what I want when testing output?
expectOutputString
stores the given string to compare against the output of the whole test, but it overwrites any previously stored string. In other words, only the last call to expectOutputString
has any effect. You must build the full output string and call expectOutputString
just once.
function test_myTest() {
$this->expectOutputString('testxzxzxzxzxz' . 'test');
echo 'test';
}
The above will fail because testxzxzxzxzxztest
does not equal the output test
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With