Created
February 24, 2012 15:31
-
-
Save radmiraal/1901648 to your computer and use it in GitHub Desktop.
Unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\FLOW3\Validation\Validator\IntegerValidator())); | |
$this->mockValidatorResolver->expects($this->any())->method('buildBaseValidatorConjunction')->will($this->returnValue(new \TYPO3\FLOW3\Validation\Validator\GenericObjectValidator())); | |
// Create validators | |
$aValidator = new \TYPO3\FLOW3\Validation\Validator\GenericObjectValidator(array('foo' => 'bar')); | |
$bValidator = $this->getAccessibleMock('TYPO3\FLOW3\Validation\Validator\CollectionValidator'); | |
$bValidator->_set('options', array('elementValidator' => 'Integer')); | |
$bValidator->_set('validatorResolver', $this->mockValidatorResolver); | |
$integerValidator = new \TYPO3\FLOW3\Validation\Validator\IntegerValidator(array('foo' => 'bar')); | |
// Add validators to properties | |
$aValidator->addPropertyValidator('b', $bValidator); | |
$aValidator->addPropertyValidator('integer', $integerValidator); | |
$result = $aValidator->validate($A)->getFlattenedErrors(); | |
print_r($result); | |
$this->assertEquals('Not an integer', $result['b.uuid'][0]['message']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There was 1 error:
Argument 1 passed to TYPO3\FLOW3\Error\Result::merge() must be an instance of TYPO3\FLOW3\Error\Result, null given, called in /Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Classes/Validation/Validator/GenericObjectValidator.php on line 101 and defined
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Classes/Error/Result.php:300
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Classes/Validation/Validator/GenericObjectValidator.php:101
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Classes/Validation/Validator/GenericObjectValidator.php:59
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Classes/Validation/Validator/AbstractValidator.php:63
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Tests/Unit/Validation/Validator/CollectionValidatorTest.php:95
/Users/rens/SSDSite/flow3/buva/Packages/Framework/TYPO3.FLOW3/Tests/BaseTestCase.php:49