You are here

class CompositeTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Tests/Constraints/CompositeTest.php \Symfony\Component\Validator\Tests\Constraints\CompositeTest

@since 2.6

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Tests\Constraints\CompositeTest extends \Symfony\Component\Validator\Tests\Constraints\PHPUnit_Framework_TestCase

Expanded class hierarchy of CompositeTest

File

vendor/symfony/validator/Tests/Constraints/CompositeTest.php, line 39

Namespace

Symfony\Component\Validator\Tests\Constraints
View source
class CompositeTest extends \PHPUnit_Framework_TestCase {
  public function testMergeNestedGroupsIfNoExplicitParentGroup() {
    $constraint = new ConcreteComposite(array(
      new NotNull(array(
        'groups' => 'Default',
      )),
      new NotBlank(array(
        'groups' => array(
          'Default',
          'Strict',
        ),
      )),
    ));
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->groups);
    $this
      ->assertEquals(array(
      'Default',
    ), $constraint->constraints[0]->groups);
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->constraints[1]->groups);
  }
  public function testSetImplicitNestedGroupsIfExplicitParentGroup() {
    $constraint = new ConcreteComposite(array(
      'constraints' => array(
        new NotNull(),
        new NotBlank(),
      ),
      'groups' => array(
        'Default',
        'Strict',
      ),
    ));
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->groups);
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->constraints[0]->groups);
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->constraints[1]->groups);
  }
  public function testExplicitNestedGroupsMustBeSubsetOfExplicitParentGroups() {
    $constraint = new ConcreteComposite(array(
      'constraints' => array(
        new NotNull(array(
          'groups' => 'Default',
        )),
        new NotBlank(array(
          'groups' => 'Strict',
        )),
      ),
      'groups' => array(
        'Default',
        'Strict',
      ),
    ));
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
    ), $constraint->groups);
    $this
      ->assertEquals(array(
      'Default',
    ), $constraint->constraints[0]->groups);
    $this
      ->assertEquals(array(
      'Strict',
    ), $constraint->constraints[1]->groups);
  }

  /**
   * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
   */
  public function testFailIfExplicitNestedGroupsNotSubsetOfExplicitParentGroups() {
    new ConcreteComposite(array(
      'constraints' => array(
        new NotNull(array(
          'groups' => array(
            'Default',
            'Foobar',
          ),
        )),
      ),
      'groups' => array(
        'Default',
        'Strict',
      ),
    ));
  }
  public function testImplicitGroupNamesAreForwarded() {
    $constraint = new ConcreteComposite(array(
      new NotNull(array(
        'groups' => 'Default',
      )),
      new NotBlank(array(
        'groups' => 'Strict',
      )),
    ));
    $constraint
      ->addImplicitGroupName('ImplicitGroup');
    $this
      ->assertEquals(array(
      'Default',
      'Strict',
      'ImplicitGroup',
    ), $constraint->groups);
    $this
      ->assertEquals(array(
      'Default',
      'ImplicitGroup',
    ), $constraint->constraints[0]->groups);
    $this
      ->assertEquals(array(
      'Strict',
    ), $constraint->constraints[1]->groups);
  }
  public function testSingleConstraintsAccepted() {
    $nestedConstraint = new NotNull();
    $constraint = new ConcreteComposite($nestedConstraint);
    $this
      ->assertEquals(array(
      $nestedConstraint,
    ), $constraint->constraints);
  }

  /**
   * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
   */
  public function testFailIfNoConstraint() {
    new ConcreteComposite(array(
      new NotNull(array(
        'groups' => 'Default',
      )),
      'NotBlank',
    ));
  }

  /**
   * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
   */
  public function testValidCantBeNested() {
    new ConcreteComposite(array(
      new Valid(),
    ));
  }

}

Members