/**
  * @test
  */
 public function collectionValidatorValidatesNestedObjectStructuresWithoutEndlessLooping()
 {
     $classNameA = 'A' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameA . '{ public $b = array(); public $integer = 5; }');
     $classNameB = 'B' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameB . '{ public $a; public $c; public $integer = "Not an integer"; }');
     $A = new $classNameA();
     $B = new $classNameB();
     $A->b = array($B);
     $B->a = $A;
     $B->c = array($A);
     $this->mockValidatorResolver->expects($this->any())->method('createValidator')->with('Integer')->will($this->returnValue(new \TYPO3\Flow\Validation\Validator\IntegerValidator()));
     $this->mockValidatorResolver->expects($this->any())->method('buildBaseValidatorConjunction')->will($this->returnValue(new \TYPO3\Flow\Validation\Validator\GenericObjectValidator()));
     // Create validators
     $aValidator = new \TYPO3\Flow\Validation\Validator\GenericObjectValidator(array());
     $this->validator->_set('options', array('elementValidator' => 'Integer', 'elementValidatorOptions' => []));
     $integerValidator = new \TYPO3\Flow\Validation\Validator\IntegerValidator(array());
     // Add validators to properties
     $aValidator->addPropertyValidator('b', $this->validator);
     $aValidator->addPropertyValidator('integer', $integerValidator);
     $result = $aValidator->validate($A)->getFlattenedErrors();
     $this->assertEquals('A valid integer number is expected.', $result['b.0'][0]->getMessage());
 }
 /**
  * @test
  */
 public function validateCanHandleRecursiveTargetsWithoutEndlessLooping()
 {
     $classNameA = 'B' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameA . '{ public $b; }');
     $classNameB = 'B' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameB . '{ public $a; }');
     $A = new $classNameA();
     $B = new $classNameB();
     $A->b = $B;
     $B->a = $A;
     $aValidator = new \TYPO3\Flow\Validation\Validator\GenericObjectValidator(array());
     $bValidator = new \TYPO3\Flow\Validation\Validator\GenericObjectValidator(array());
     $aValidator->addPropertyValidator('b', $bValidator);
     $bValidator->addPropertyValidator('a', $aValidator);
     $this->assertFalse($aValidator->validate($A)->hasErrors());
 }