assertInstanceOf()
1 | assertInstanceOf( $expected , $actual [, $message = '' ]) |
Reports an error identified by $message
if $actual
is not an instance of $expected
.
assertNotInstanceOf()
is the inverse of this assertion and takes the same arguments.
assertAttributeInstanceOf()
and assertAttributeNotInstanceOf()
are convenience wrappers that can be applied to a public
, protected
, or private
attribute of a class or object.
Example A.29: Usage of assertInstanceOf()
1 2 3 4 5 6 7 8 9 10 11 | <?php use PHPUnit\Framework\TestCase; class InstanceOfTest extends TestCase { public function testFailure() { $this ->assertInstanceOf(RuntimeException:: class , new Exception); } } ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | phpunit InstanceOfTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.00Mb There was 1 failure: 1) InstanceOfTest::testFailure Failed asserting that Exception Object (...) is an instance of class "RuntimeException". /home/sb/InstanceOfTest.php:6 FAILURES! Tests: 1, Assertions: 1, Failures: 1. |
Please login to continue.