コード例 #1
0
 /**
  * @test
  */
 public function returnsAndRendersThenChildIfResultsHaveErrors()
 {
     $result = new Result();
     $result->addError(new Error('I am an error', 1386163707));
     /** @var $requestMock \PHPUnit_Framework_MockObject_MockObject */
     $requestMock = $this->request;
     $requestMock->expects($this->once())->method('getInternalArgument')->with('__submittedArgumentValidationResults')->will($this->returnValue($result));
     $this->viewHelper->expects($this->once())->method('renderThenChild')->will($this->returnValue('ThenChild'));
     $this->assertEquals('ThenChild', $this->viewHelper->render());
 }
コード例 #2
0
 /**
  * @test
  */
 public function validatorConjunctionReturnsErrorsIfOneValidatorReturnsErrors()
 {
     $validatorConjunction = new ConjunctionValidator([]);
     $validatorObject = $this->createMock(ValidatorInterface::class);
     $errors = new Error\Result();
     $errors->addError(new Error\Error('Error', 123));
     $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors));
     $validatorConjunction->addValidator($validatorObject);
     $this->assertTrue($validatorConjunction->validate('some subject')->hasErrors());
 }
コード例 #3
0
 /**
  * @test
  */
 public function validateReturnsAllErrorsIfAllValidatorsReturnErrrors()
 {
     $validatorDisjunction = new DisjunctionValidator([]);
     $error1 = new Error\Error('Error', 123);
     $error2 = new Error\Error('Error2', 123);
     $errors1 = new Error\Result();
     $errors1->addError($error1);
     $validatorObject = $this->createMock(ValidatorInterface::class);
     $validatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors1));
     $errors2 = new Error\Result();
     $errors2->addError($error2);
     $secondValidatorObject = $this->createMock(ValidatorInterface::class);
     $secondValidatorObject->expects($this->any())->method('validate')->will($this->returnValue($errors2));
     $validatorDisjunction->addValidator($validatorObject);
     $validatorDisjunction->addValidator($secondValidatorObject);
     $this->assertEquals([$error1, $error2], $validatorDisjunction->validate('some subject')->getErrors());
 }
コード例 #4
0
ファイル: ArgumentTest.php プロジェクト: neos/flow
 /**
  * @test
  */
 public function setValueShouldSetValidationErrorsIfValidatorIsSetAndValidationFailed()
 {
     $error = new FLowError\Error('Some Error', 1234);
     $mockValidator = $this->createMock(ValidatorInterface::class);
     $validationMessages = new FLowError\Result();
     $validationMessages->addError($error);
     $mockValidator->expects($this->once())->method('validate')->with('convertedValue')->will($this->returnValue($validationMessages));
     $this->simpleValueArgument->setValidator($mockValidator);
     $this->setupPropertyMapperAndSetValue();
     $this->assertEquals([$error], $this->simpleValueArgument->getValidationResults()->getErrors());
 }
コード例 #5
0
 /**
  * @test
  */
 public function getValidationResultsShouldFetchAllValidationResltsFromArguments()
 {
     $error1 = new FlowError\Error('Validation error', 1234);
     $error2 = new FlowError\Error('Validation error 2', 1235);
     $results1 = new FlowError\Result();
     $results1->addError($error1);
     $results2 = new FlowError\Result();
     $results2->addError($error2);
     $argument1 = $this->getMockBuilder(Argument::class)->setMethods(['getValidationResults'])->setConstructorArgs(['name1', 'string'])->getMock();
     $argument1->expects($this->once())->method('getValidationResults')->will($this->returnValue($results1));
     $argument2 = $this->getMockBuilder(Argument::class)->setMethods(['getValidationResults'])->setConstructorArgs(['name2', 'string'])->getMock();
     $argument2->expects($this->once())->method('getValidationResults')->will($this->returnValue($results2));
     $arguments = new Arguments();
     $arguments->addArgument($argument1);
     $arguments->addArgument($argument2);
     $this->assertSame(['name1' => [$error1], 'name2' => [$error2]], $arguments->getValidationResults()->getFlattenedErrors());
 }
コード例 #6
0
ファイル: ResultTest.php プロジェクト: neos/error-messages
 /**
  * @test
  */
 public function mergeShouldMergeTwoResults()
 {
     $notice1 = $this->getMockMessage('Notice');
     $notice2 = $this->getMockMessage('Notice');
     $notice3 = $this->getMockMessage('Notice');
     $warning1 = $this->getMockMessage('Warning');
     $warning2 = $this->getMockMessage('Warning');
     $warning3 = $this->getMockMessage('Warning');
     $error1 = $this->getMockMessage('Error');
     $error2 = $this->getMockMessage('Error');
     $error3 = $this->getMockMessage('Error');
     $otherResult = new Result();
     $otherResult->addNotice($notice1);
     $otherResult->forProperty('foo.bar')->addNotice($notice2);
     $this->result->forProperty('foo')->addNotice($notice3);
     $otherResult->addWarning($warning1);
     $this->result->addWarning($warning2);
     $this->result->addWarning($warning3);
     $otherResult->forProperty('foo')->addError($error1);
     $otherResult->forProperty('foo')->addError($error2);
     $otherResult->addError($error3);
     $this->result->merge($otherResult);
     $this->assertSame([$notice1], $this->result->getNotices(), 'Notices are not merged correctly without recursion');
     $this->assertSame([$notice3], $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.');
     $this->assertSame([$notice2], $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.');
     $this->assertSame([$warning2, $warning3, $warning1], $this->result->getWarnings());
     $this->assertSame([$error3], $this->result->getErrors());
     $this->assertSame([$error1, $error2], $this->result->forProperty('foo')->getErrors());
 }
コード例 #7
0
 /**
  * Creates a new validation error object and adds it to $this->errors
  *
  * @param string $message The error message
  * @param integer $code The error code (a unix timestamp)
  * @param array $arguments Arguments to be replaced in message
  * @return void
  * @api
  */
 protected function addError($message, $code, array $arguments = [])
 {
     $this->result->addError(new ValidationError($message, $code, $arguments));
 }
コード例 #8
0
 /**
  * @test
  */
 public function validateDetectsFailuresInRecursiveTargetsII()
 {
     $classNameA = 'A' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameA . '{ public $b; public $uuid = 0xF; }');
     $classNameB = 'B' . md5(uniqid(mt_rand(), true));
     eval('class ' . $classNameB . '{ public $a; public $uuid = 0xF; }');
     $A = new $classNameA();
     $B = new $classNameB();
     $A->b = $B;
     $B->a = $A;
     $aValidator = $this->getValidator();
     $bValidator = $this->getValidator();
     $aValidator->addPropertyValidator('b', $bValidator);
     $bValidator->addPropertyValidator('a', $aValidator);
     $error1 = new Error\Error('error1', 123);
     $result1 = new Error\Result();
     $result1->addError($error1);
     $mockUuidValidator = $this->createMock(ValidatorInterface::class);
     $mockUuidValidator->expects($this->any())->method('validate')->with(0xf)->will($this->returnValue($result1));
     $aValidator->addPropertyValidator('uuid', $mockUuidValidator);
     $bValidator->addPropertyValidator('uuid', $mockUuidValidator);
     $this->assertSame(['b.uuid' => [$error1], 'uuid' => [$error1]], $aValidator->validate($A)->getFlattenedErrors());
 }
コード例 #9
0
 /**
  * Validate a null value with the given schema
  *
  * @param mixed $value
  * @param array $schema
  * @return ErrorResult
  */
 protected function validateNullType($value, array $schema)
 {
     $result = new ErrorResult();
     if ($value !== null) {
         $result->addError($this->createError('type=NULL', 'type=' . gettype($value)));
     }
     return $result;
 }