You are here

protected function AbstractConstraintValidatorTest::createContext in Plug 7

7 calls to AbstractConstraintValidatorTest::createContext()
AbstractConstraintValidatorTest::setGroup in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
AbstractConstraintValidatorTest::setObject in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
AbstractConstraintValidatorTest::setProperty in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
AbstractConstraintValidatorTest::setPropertyPath in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php
AbstractConstraintValidatorTest::setRoot in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php

... See full list

File

lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php, line 113

Class

AbstractConstraintValidatorTest
@since 2.5.3

Namespace

Symfony\Component\Validator\Tests\Constraints

Code

protected function createContext() {
  $translator = $this
    ->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
  if (Validation::API_VERSION_2_4 === $this
    ->getApiVersion()) {
    return $this
      ->getMockBuilder('Symfony\\Component\\Validator\\ExecutionContext')
      ->setConstructorArgs(array(
      new StubGlobalExecutionContext($this->root),
      $translator,
      null,
      $this->metadata,
      $this->value,
      $this->group,
      $this->propertyPath,
    ))
      ->setMethods(array(
      'validate',
      'validateValue',
    ))
      ->getMock();
  }
  $validator = $this
    ->getMock('Symfony\\Component\\Validator\\Validator\\ValidatorInterface');
  $contextualValidator = $this
    ->getMock('Symfony\\Component\\Validator\\Validator\\ContextualValidatorInterface');
  switch ($this
    ->getApiVersion()) {
    case Validation::API_VERSION_2_5:
      $context = new ExecutionContext($validator, $this->root, $translator);
      break;
    case Validation::API_VERSION_2_5_BC:
      $context = new LegacyExecutionContext($validator, $this->root, $this
        ->getMock('Symfony\\Component\\Validator\\MetadataFactoryInterface'), $translator);
      break;
    default:
      throw new \RuntimeException('Invalid API version');
  }
  $context
    ->setGroup($this->group);
  $context
    ->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
  $context
    ->setConstraint($this->constraint);
  $validator
    ->expects($this
    ->any())
    ->method('inContext')
    ->with($context)
    ->will($this
    ->returnValue($contextualValidator));
  return $context;
}