public function Framework_ConstraintTest::testConstraintCallback

@covers PHPUnit_Framework_Constraint_Callback

File

drupal/core/vendor/phpunit/phpunit/Tests/Framework/ConstraintTest.php, line 1814

Class

Framework_ConstraintTest
@package PHPUnit @author Sebastian Bergmann <sebastian@phpunit.de> @author Bernhard Schussek <bschussek@2bepublished.at> @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de> @license …

Code

public function testConstraintCallback() {
  $closureReflect = function ($parameter) {
    return $parameter;
  };
  $closureWithoutParameter = function () {
    return TRUE;
  };
  $constraint = PHPUnit_Framework_Assert::callback($closureWithoutParameter);
  $this
    ->assertTrue($constraint
    ->evaluate('', '', TRUE));
  $constraint = PHPUnit_Framework_Assert::callback($closureReflect);
  $this
    ->assertTrue($constraint
    ->evaluate(TRUE, '', TRUE));
  $this
    ->assertFalse($constraint
    ->evaluate(FALSE, '', TRUE));
  $callback = array(
    $this,
    'callbackReturningTrue',
  );
  $constraint = PHPUnit_Framework_Assert::callback($callback);
  $this
    ->assertTrue($constraint
    ->evaluate(FALSE, '', TRUE));
  $callback = array(
    'Framework_ConstraintTest',
    'staticCallbackReturningTrue',
  );
  $constraint = PHPUnit_Framework_Assert::callback($callback);
  $this
    ->assertTrue($constraint
    ->evaluate(NULL, '', TRUE));
  $this
    ->assertEquals('is accepted by specified callback', $constraint
    ->toString());
}