My first assumption about the problem (that you are not using one of the PHPUnit_Framework_Constraint_* and self::assertThat ) turned out to be completely inappropriate! The actual answer is that phpUnit helps filter out something in its own code base from the stack trace and simply leaves functions in user space!
The code that does this can be found in /path/to/PHPUnit/Util/Filter.php ( isFiltered / isFiltered /to isFiltered / isFiltered / isFiltered php on my machine), and the functions of interest are getFilteredStacktrace and isFiltered .
If you want to control this behavior, add your custom statements to a class derived from PHPUnit_Framework_TestCase , and then derive tests from this class. In your custom class file, place the call somewhere in addFileToFilter , as shown below:
class My_Base_TestCase extends PHPUnit_Framework_TestCase{ public static function assertFoo($expected, $actual) { self::assertEquals($expected, $actual); } } PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
Then in another file you have:
class CustomTest extends My_Base_TestCase{ public function testSomething2(){ $this->assertFoo( 8, 5+4 ); } }
and it will behave exactly like the built-in assertEquals() .
DISCLAIMER: Use of undocumented behavior! I will try to find out if this mechanism is reasonable for the future.
source share