<commit_before><?php

/**
 * This file is part of the Zymfony library.
 *
 *  (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Zymfony\Component\Validator;

/**
 * @author <NAME> <<EMAIL>>
 */
class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
{
    protected $context;
    protected $validator;

    protected function setUp()
    {
        $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
        $this->validator = new ConstraintValidator();
        $this->validator->initialize($this->context);
    }

    /**
     * @dataProvider testValidValueDataProvider
     */
    public function testValidValue($validator, $options, $value)
    {
        $this->context
            ->expects($this->never())
            ->method('addViolation')
        ;

        $this->validator->validate(
            $value,
            new Constraint(array(
                'validator' => $validator,
                'options'   => $options
            ))
        );
    }

    public function testValidValueDataProvider()
    {
        return array(
            array(
                'Zend\Validator\StringLength',
                array('min' => 3, 'max' => 5),
                'four'
            ),
            array(
                'Zend\Validator\CreditCard',
                array(),
                '378282246310005'
            ),
        );
    }

    /**
     * @dataProvider testInvalidValueDataProvider
     */
    public function testInvalidValue($validator, $options, $value, $message)
    {
        $this->context
            ->expects($this->once())
            ->method('addViolation')
            ->with(
                $message,
                $this->identicalTo(array()),
                $this->identicalTo($value)
            );
        ;

        $this->validator->validate(
            $value,
            new Constraint(array(
                'validator' => $validator,
                'options'   => $options
            ))
        );
    }

    public function testInvalidValueDataProvider()
    {
        return array(
            array(
                'Zend\Validator\StringLength',
                array('min' => 3, 'max' => 5),
                'loooooooooooooooooong',
                'The input is more than 5 characters long'
            ),
            array(
                'Zend\Validator\CreditCard',
                array(),
                'foo',
                'The input must contain only digits'
            ),
            array(
                'Zend\Validator\CreditCard',
                array(),
                '1234',
                'The input is not from an allowed institute'
            ),
        );
    }
}<commit_msg>Better tests.<commit_after><?php

/**
 * This file is part of the Zymfony library.
 *
 *  (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Zymfony\Component\Validator;

/**
 * @author <NAME> <<EMAIL>>
 */
class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
{
    protected $context;
    protected $validator;

    protected function setUp()
    {
        $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
        $this->validator = new ConstraintValidator();
        $this->validator->initialize($this->context);
    }

    /**
     * @dataProvider testValidValueDataProvider
     */
    public function testValidValue($validator, $options, $value)
    {
        $this->context
            ->expects($this->never())
            ->method('addViolation')
        ;

        $this->validator->validate(
            $value,
            new Constraint(array(
                'validator' => $validator,
                'options'   => $options
            ))
        );
    }

    public function testValidValueDataProvider()
    {
        return array(
            array(
                'Zend\Validator\StringLength',
                array('min' => 3, 'max' => 5),
                'four'
            ),
            array(
                'Zend\Validator\CreditCard',
                array(),
                '378282246310005'
            ),
        );
    }

    /**
     * @dataProvider testInvalidValueDataProvider
     */
    public function testInvalidValue($validator, $options, $value, $message)
    {
        $this->context
            ->expects($this->once())
            ->method('addViolation')
            ->with(
                $message,
                $this->identicalTo(array()),
                $this->identicalTo($value)
            );
        ;

        $this->validator->validate(
            $value,
            new Constraint(array(
                'validator' => $validator,
                'options'   => $options
            ))
        );
    }

    public function testInvalidValueDataProvider()
    {
        return array(
            array(
                'Zend\Validator\StringLength',
                array('min' => 3, 'max' => 5),
                'loooooooooooooooooong',
                'The input is more than 5 characters long'
            ),
            array(
                'Zend\Validator\CreditCard',
                array(),
                'foo',
                'The input must contain only digits'
            ),
            array(
                'Zend\Validator\CreditCard',
                array('type' => \Zend\Validator\CreditCard::AMERICAN_EXPRESS),
                '4111111111111111',
                'The input is not from an allowed institute'
            ),
        );
    }
}
{'fraction_non_alphanumeric': 0.12170596393897365, 'fraction_numerical': 0.010402219140083218, 'mean_word_length': 1.4802235597592432, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105963', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1466, 'n_words': 312}