ValidatorTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Symfony\Tests\Component\Validator;
  3. use Symfony\Component\Validator\Constraint;
  4. use Symfony\Component\Validator\Validator;
  5. use Symfony\Component\Validator\ConstraintViolation;
  6. use Symfony\Component\Validator\ConstraintViolationList;
  7. use Symfony\Component\Validator\Mapping\Metadata;
  8. use Symfony\Component\Validator\Specification\PropertySpecification;
  9. use Symfony\Component\Validator\Specification\ClassSpecification;
  10. use Symfony\Component\Validator\Specification\Specification;
  11. class ValidatorTest_Class
  12. {
  13. public $firstName = 'Bernhard';
  14. public $reference;
  15. public function getLastName()
  16. {
  17. return 'Schussek';
  18. }
  19. public function isAustralian()
  20. {
  21. return false;
  22. }
  23. }
  24. class ValidatorTest extends \PHPUnit_Framework_TestCase
  25. {
  26. public function testValidatePropertyConstraint()
  27. {
  28. /*
  29. $subject = new ValidatorTest_Class();
  30. $subjectClass = get_class($subject);
  31. $constraint = new Constraint();
  32. $property = new PropertySpecification($subjectClass, 'firstName', array($constraint));
  33. $class = new ClassSpecification($subjectClass, array($property));
  34. $specification = new Specification(array($class));
  35. $metadata = new Metadata($specification);
  36. $validatorMock = $this->getMock('Symfony\Component\Validator\ConstraintValidatorInterface');
  37. $validatorMock->expects($this->once())
  38. ->method('isValid')
  39. ->with($this->equalTo('Bernhard'), $this->equalTo($constraint))
  40. ->will($this->returnValue(false));
  41. $validatorMock->expects($this->atLeastOnce())
  42. ->method('getMessageTemplate')
  43. ->will($this->returnValue('message'));
  44. $validatorMock->expects($this->atLeastOnce())
  45. ->method('getMessageParameters')
  46. ->will($this->returnValue(array('param' => 'value')));
  47. $factoryMock = $this->getMock('Symfony\Component\Validator\ConstraintValidatorFactoryInterface');
  48. $factoryMock->expects($this->once())
  49. ->method('getInstance')
  50. ->with($this->equalTo($constraint->validatedBy()))
  51. ->will($this->returnValue($validatorMock));
  52. $validator = new Validator($metadata, $factoryMock);
  53. $builder = new PropertyPathBuilder();
  54. $expected = new ConstraintViolationList();
  55. $expected->add(new ConstraintViolation(
  56. 'message',
  57. array('param' => 'value'),
  58. $subjectClass,
  59. $builder->atProperty('firstName')->getPropertyPath(),
  60. 'Bernhard'
  61. ));
  62. $this->assertEquals($expected, $validator->validateProperty($subject, 'firstName'));
  63. */
  64. }
  65. }