You are here

public function Abstract2Dot5ApiTest::testAccessCurrentObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php \Symfony\Component\Validator\Tests\Validator\Abstract2Dot5ApiTest::testAccessCurrentObject()

File

vendor/symfony/validator/Tests/Validator/Abstract2Dot5ApiTest.php, line 648

Class

Abstract2Dot5ApiTest
Verifies that a validator satisfies the API of Symfony 2.5+.

Namespace

Symfony\Component\Validator\Tests\Validator

Code

public function testAccessCurrentObject() {
  $test = $this;
  $called = false;
  $entity = new Entity();
  $entity->firstName = 'Bernhard';
  $callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, &$called) {
    $called = true;
    $test
      ->assertSame($entity, $context
      ->getObject());
  };
  $this->metadata
    ->addConstraint(new Callback($callback));
  $this->metadata
    ->addPropertyConstraint('firstName', new Callback($callback));
  $this->validator
    ->validate($entity);
  $this
    ->assertTrue($called);
}