* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Tests\Extension\Validator; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser; use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Validator\Constraints\Email; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Range; use Symfony\Component\Validator\Constraints\IsTrue; use Symfony\Component\Validator\Constraints\Type; use Symfony\Component\Validator\Mapping\ClassMetadata; /** * @author franek * @author Bernhard Schussek */ class ValidatorTypeGuesserTest extends TestCase { const TEST_CLASS = 'Symfony\Component\Form\Tests\Extension\Validator\ValidatorTypeGuesserTest_TestClass'; const TEST_PROPERTY = 'property'; /** * @var ValidatorTypeGuesser */ private $guesser; /** * @var ClassMetadata */ private $metadata; /** * @var \PHPUnit_Framework_MockObject_MockObject */ private $metadataFactory; protected function setUp() { $this->metadata = new ClassMetadata(self::TEST_CLASS); $this->metadataFactory = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface')->getMock(); $this->metadataFactory->expects($this->any()) ->method('getMetadataFor') ->with(self::TEST_CLASS) ->will($this->returnValue($this->metadata)); $this->guesser = new ValidatorTypeGuesser($this->metadataFactory); } public function guessRequiredProvider() { return array( array(new NotNull(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)), array(new NotBlank(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)), array(new IsTrue(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)), array(new Length(10), new ValueGuess(false, Guess::LOW_CONFIDENCE)), array(new Range(array('min' => 1, 'max' => 20)), new ValueGuess(false, Guess::LOW_CONFIDENCE)), ); } /** * @dataProvider guessRequiredProvider */ public function testGuessRequired($constraint, $guess) { // add distracting constraint $this->metadata->addPropertyConstraint(self::TEST_PROPERTY, new Email()); // add constraint under test $this->metadata->addPropertyConstraint(self::TEST_PROPERTY, $constraint); $this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY)); } public function testGuessRequiredReturnsFalseForUnmappedProperties() { $this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY)); } public function testGuessMaxLengthForConstraintWithMaxValue() { $constraint = new Length(array('max' => '2')); $result = $this->guesser->guessMaxLengthForConstraint($constraint); $this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result); $this->assertEquals(2, $result->getValue()); $this->assertEquals(Guess::HIGH_CONFIDENCE, $result->getConfidence()); } public function testGuessMaxLengthForConstraintWithMinValue() { $constraint = new Length(array('min' => '2')); $result = $this->guesser->guessMaxLengthForConstraint($constraint); $this->assertNull($result); } public function maxLengthTypeProvider() { return array( array('double'), array('float'), array('numeric'), array('real'), ); } /** * @dataProvider maxLengthTypeProvider */ public function testGuessMaxLengthForConstraintWithType($type) { $constraint = new Type($type); $result = $this->guesser->guessMaxLengthForConstraint($constraint); $this->assertInstanceOf('Symfony\Component\Form\Guess\ValueGuess', $result); $this->assertNull($result->getValue()); $this->assertEquals(Guess::MEDIUM_CONFIDENCE, $result->getConfidence()); } } class ValidatorTypeGuesserTest_TestClass { private $property; } __halt_compiler();----SIGNATURE:----Qo388VZ2AlS6ohvYf0xHuCQq/aKySB+qK7QaCB82Tb7tEKV/7NYsUyEDX/+lIpXIQETm03YkZnz32fuz9wAzX+8eA47r+OdUJnqphBkQe2lR6euKY4wQNXA8wU9a+7KilwGZqHunbLK/mGjr2WknEBphVJX0esGQ7YkZuN3ifSuBjPHw1HUtFjiNUN4fp810r6QtwLc1zKr0yF1++XgARNeQ+QZczB5wnyKbe9tpcSu+61WIG49pBJEmRPwhWt/Az3QpndMH5BvWrCHPFOToT870fxcEBQ+E8pXiazCvZMS/c9v1aUABAlsQxRXkZ9hfCJW6p6oGXkS3LJxDWhCqOSlWax/WOKjyh+PBJatRmyCpw2C6g7SQJT2yt0hbmlYDeudEKC/DGNfeBAGA17KZawljLzDJTp7ASGq4JbKSEObdgt8EGdatQQObBNbquur+pPfkVg/eSyk8ZE/8+/P0+YLGyDfVDmOiKe+/xTYckiIFt4thLpcDHSaCTOZ7hCV5vavKVXEeVXn0R0pp1jQKNEcim5mDUC1cYNO2g6mzEAmIqU+nq7PEch8avJKGQVzOM+tuseqMmTMKdXuLnx4qcICRb09aQcBQZrTandO3r3MVPuDK1BsLTHdSSmbBrfSrD9fYeqycucZkO3gy8Ld+sJtFnzuCQN0Ac/wiW2czMmM=----ATTACHMENT:----NjU2ODEyNDk4MjQ4MDkyNyAzNDI3MDc5NjQ2MjQ4ODgyIDUzMDAyMzYxNTg4ODg0NjQ=