Skip to content

Commit

Permalink
Increase test coverage.
Browse files Browse the repository at this point in the history
Cover off previously uncovered code paths.
  • Loading branch information
markstory committed Jan 2, 2016
1 parent bd798d9 commit d58bb11
Showing 1 changed file with 68 additions and 7 deletions.
75 changes: 68 additions & 7 deletions tests/TestCase/Validation/ValidatorTest.php
Expand Up @@ -1084,6 +1084,18 @@ public function testLengthBetween()
$this->assertNotEmpty($validator->errors(['username' => 'foo']));
}

/**
* Tests the lengthBetween proxy method
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testLengthBetweenFailure()
{
$validator = new Validator();
$validator->lengthBetween('username', [7]);
}

/**
* Tests the creditCard proxy method
*
Expand Down Expand Up @@ -1272,6 +1284,18 @@ public function testIps()
$this->assertNotEmpty($validator->errors(['username' => 'not ip']));
}

/**
* Tests the minLength proxy method
*
* @return void
*/
public function testMinLength()
{
$validator = new Validator();
$this->assertProxyMethod($validator, 'minLength', 2, [2]);
$this->assertNotEmpty($validator->errors(['username' => 'a']));
}

/**
* Tests the maxLength proxy method
*
Expand All @@ -1284,6 +1308,19 @@ public function testMaxLength()
$this->assertNotEmpty($validator->errors(['username' => 'aaa']));
}

/**
* Tests the numeric proxy method
*
* @return void
*/
public function testNumeric()
{
$validator = new Validator();
$this->assertProxyMethod($validator, 'numeric');
$this->assertEmpty($validator->errors(['username' => '22']));
$this->assertNotEmpty($validator->errors(['username' => 'a']));
}

/**
* Tests the naturalNumber proxy method
*
Expand Down Expand Up @@ -1320,6 +1357,17 @@ public function testRange()
$this->assertNotEmpty($validator->errors(['username' => 5]));
}

/**
* Tests the range failure case
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testRangeFailure()
{
$validator = new Validator();
$validator->range('username', [1]);
}
/**
* Tests the url proxy method
*
Expand Down Expand Up @@ -1442,6 +1490,19 @@ public function testUtf8Extended()
$this->assertEmpty($validator->errors(['username' => $extended]));
}

/**
* Tests the email proxy method
*
* @return void
*/
public function testEmail()
{
$validator = new Validator();
$validator->email('username');
$this->assertEmpty($validator->errors(['username' => 'test@example.com']));
$this->assertNotEmpty($validator->errors(['username' => 'not an email']));
}

/**
* Tests the integer proxy method
*
Expand All @@ -1464,11 +1525,11 @@ protected function assertProxyMethod($validator, $method, $extra = null, $pass =
}

$rule = $validator->field('username')->rule($method);
$this->assertNull($rule->get('message'));
$this->assertNull($rule->get('on'));
$this->assertEquals($name, $rule->get('rule'));
$this->assertEquals($pass, $rule->get('pass'));
$this->assertEquals('default', $rule->get('provider'));
$this->assertNull($rule->get('message'), 'Message is present when it should not be');
$this->assertNull($rule->get('on'), 'On clause is present when it should not be');
$this->assertEquals($name, $rule->get('rule'), 'Rule name does not match');
$this->assertEquals($pass, $rule->get('pass'), 'Passed options are different');
$this->assertEquals('default', $rule->get('provider'), 'Provider does not match');

if ($extra !== null) {
$validator->{$method}('username', $extra, 'the message', 'create');
Expand All @@ -1477,7 +1538,7 @@ protected function assertProxyMethod($validator, $method, $extra = null, $pass =
}

$rule = $validator->field('username')->rule($method);
$this->assertEquals('the message', $rule->get('message'));
$this->assertEquals('create', $rule->get('on'));
$this->assertEquals('the message', $rule->get('message'), 'Error messages are not the same');
$this->assertEquals('create', $rule->get('on'), 'On clause is wrong');
}
}

0 comments on commit d58bb11

Please sign in to comment.