You are here

public function Framework_ConstraintTest::testConstraintIsInstanceOf in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/tests/Framework/ConstraintTest.php \Framework_ConstraintTest::testConstraintIsInstanceOf()

@covers PHPUnit_Framework_Constraint_IsInstanceOf @covers PHPUnit_Framework_Assert::isInstanceOf @covers PHPUnit_Framework_Constraint::count @covers PHPUnit_Framework_TestFailure::exceptionToString

File

vendor/phpunit/phpunit/tests/Framework/ConstraintTest.php, line 1173

Class

Framework_ConstraintTest
@since Class available since Release 3.0.0

Code

public function testConstraintIsInstanceOf() {
  $constraint = PHPUnit_Framework_Assert::isInstanceOf('Exception');
  $this
    ->assertFalse($constraint
    ->evaluate(new stdClass(), '', true));
  $this
    ->assertTrue($constraint
    ->evaluate(new Exception(), '', true));
  $this
    ->assertEquals('is instance of class "Exception"', $constraint
    ->toString());
  $this
    ->assertEquals(1, count($constraint));
  $interfaceConstraint = PHPUnit_Framework_Assert::isInstanceOf('Countable');
  $this
    ->assertFalse($interfaceConstraint
    ->evaluate(new stdClass(), '', true));
  $this
    ->assertTrue($interfaceConstraint
    ->evaluate(new ArrayObject(), '', true));
  $this
    ->assertEquals('is instance of interface "Countable"', $interfaceConstraint
    ->toString());
  try {
    $constraint
      ->evaluate(new stdClass());
  } catch (PHPUnit_Framework_ExpectationFailedException $e) {
    $this
      ->assertEquals(<<<EOF
Failed asserting that stdClass Object () is an instance of class "Exception".

EOF
, PHPUnit_Framework_TestFailure::exceptionToString($e));
    return;
  }
  $this
    ->fail();
}