예제 #1
0
    /**
     * Ensures that the validator follows expected behavior
     *
     * @return void
     */
    public function testBasic()
    {
        /**
         * The elements of each array are, in order:
         *      - minimum
         *      - expected validation result
         *      - array of test input values
         */
        $valuesExpected = array(
            array(0, true, array(0.01, 1, 100)),
            array(0, false, array(0, 0.00, -0.01, -1, -100)),
            array('a', true, array('b', 'c', 'd')),
            array('z', false, array('x', 'y', 'z')),
            array(array('min' => 0, 'inclusive' => true), true, array(0, 0.00, 0.01, 1, 100)),
            array(array('min' => 0, 'inclusive' => true), false, array(-0.01, -1, -100)),
            array(array('min' => 0, 'inclusive' => false), true, array(0.01, 1, 100)),
            array(array('min' => 0, 'inclusive' => false), false, array(0, 0.00, -0.01, -1, -100))
        );

        foreach ($valuesExpected as $element) {
            $validator = new GreaterThan($element[0]);
            foreach ($element[2] as $input) {
                $this->assertEquals($element[1], $validator->isValid($input));
            }
        }
    }
예제 #2
0
 public function testCorrectNotInclusiveMessageReturn()
 {
     $valuesToValidate = array(0, 0.5, 5, 9);
     foreach ($valuesToValidate as $value) {
         $validator = new GreaterThan(array('min' => 10, 'inclusive' => true));
         $validator->isValid($value);
         $message = $validator->getMessages();
         $this->assertArrayHaskey('notGreaterThanInclusive', $message);
         $this->assertEquals($message['notGreaterThanInclusive'], "The input is not greater or equal than '10'");
     }
 }