mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Tests code style fixes
This commit is contained in:
parent
f70e27af56
commit
c52612f86c
@ -897,7 +897,14 @@ class Validator
|
|||||||
return $isInstanceOf;
|
return $isInstanceOf;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validate optional field
|
/**
|
||||||
|
* Validate optional field
|
||||||
|
*
|
||||||
|
* @param $field
|
||||||
|
* @param $value
|
||||||
|
* @param $params
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function validateOptional($field, $value, $params)
|
protected function validateOptional($field, $value, $params)
|
||||||
{
|
{
|
||||||
//Always return true
|
//Always return true
|
||||||
@ -997,7 +1004,7 @@ class Validator
|
|||||||
}
|
}
|
||||||
// Catches the case where the data isn't an array or object
|
// Catches the case where the data isn't an array or object
|
||||||
if (is_scalar($data)) {
|
if (is_scalar($data)) {
|
||||||
return array(NULL, false);
|
return array(null, false);
|
||||||
}
|
}
|
||||||
$identifier = array_shift($identifiers);
|
$identifier = array_shift($identifiers);
|
||||||
// Glob match
|
// Glob match
|
||||||
@ -1012,8 +1019,7 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array($values, true);
|
return array($values, true);
|
||||||
}
|
} // Dead end, abort
|
||||||
// Dead end, abort
|
|
||||||
elseif ($identifier === null || ! isset($data[$identifier])) {
|
elseif ($identifier === null || ! isset($data[$identifier])) {
|
||||||
if ($allow_empty){
|
if ($allow_empty){
|
||||||
//when empty values are allowed, we only care if the key exists
|
//when empty values are allowed, we only care if the key exists
|
||||||
@ -1083,7 +1089,9 @@ class Validator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($set_to_break) break;
|
if ($set_to_break) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count($this->errors()) === 0;
|
return count($this->errors()) === 0;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class BaseTestCase extends TestCase
|
|||||||
|
|
||||||
protected function resetProperty($name, $value = null)
|
protected function resetProperty($name, $value = null)
|
||||||
{
|
{
|
||||||
$prop = new ReflectionProperty('Valitron\Validator', $name);
|
$prop = new \ReflectionProperty('Valitron\Validator', $name);
|
||||||
$prop->setAccessible(true);
|
$prop->setAccessible(true);
|
||||||
$prop->setValue($value);
|
$prop->setValue($value);
|
||||||
$prop->setAccessible(false);
|
$prop->setAccessible(false);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
class ErrorMessagesTest extends BaseTestCase
|
class ErrorMessagesTest extends BaseTestCase
|
||||||
@ -66,7 +67,8 @@ class ErrorMessagesTest extends BaseTestCase
|
|||||||
$this->assertEquals($v->errors('name'), array('A value is required for Name'));
|
$this->assertEquals($v->errors('name'), array('A value is required for Name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMessageWithFieldAndLabelSet(){
|
public function testMessageWithFieldAndLabelSet()
|
||||||
|
{
|
||||||
$v = new Validator(array('name' => ''), array(), 'en', __DIR__ . '/../lang');
|
$v = new Validator(array('name' => ''), array(), 'en', __DIR__ . '/../lang');
|
||||||
$v->rule('required', 'name')->label('my name');
|
$v->rule('required', 'name')->label('my name');
|
||||||
$v->validate();
|
$v->validate();
|
||||||
|
|||||||
@ -9,7 +9,7 @@ class LangTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lang defined statically should not be overrided by constructor default
|
* Lang defined statically should not be override by constructor default
|
||||||
*/
|
*/
|
||||||
public function testLangDefinedStatically()
|
public function testLangDefinedStatically()
|
||||||
{
|
{
|
||||||
@ -20,7 +20,7 @@ class LangTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LangDir defined statically should not be overrided by constructor default
|
* LangDir defined statically should not be override by constructor default
|
||||||
*/
|
*/
|
||||||
public function testLangDirDefinedStatically()
|
public function testLangDirDefinedStatically()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
use Valitron\Validator;
|
|
||||||
|
|
||||||
|
use Valitron\Validator;
|
||||||
|
|
||||||
class MapRulesTest extends BaseTestCase
|
class MapRulesTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function testMapSingleFieldRules()
|
public function testMapSingleFieldRules()
|
||||||
{
|
{
|
||||||
|
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'required',
|
'required',
|
||||||
array('lengthMin', 4)
|
array('lengthMin', 4)
|
||||||
@ -24,7 +23,6 @@ class MapRulesTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testSingleFieldDot()
|
public function testSingleFieldDot()
|
||||||
{
|
{
|
||||||
|
|
||||||
$v = new Valitron\Validator(array(
|
$v = new Valitron\Validator(array(
|
||||||
'settings' => array(
|
'settings' => array(
|
||||||
array('threshold' => 50),
|
array('threshold' => 50),
|
||||||
@ -36,7 +34,6 @@ class MapRulesTest extends BaseTestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMapMultipleFieldsRules()
|
public function testMapMultipleFieldsRules()
|
||||||
@ -60,7 +57,6 @@ class MapRulesTest extends BaseTestCase
|
|||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
$this->assertFalse($v->errors('myField1'));
|
$this->assertFalse($v->errors('myField1'));
|
||||||
$this->assertEquals(2, sizeof($v->errors('myField2')));
|
$this->assertEquals(2, sizeof($v->errors('myField2')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCustomMessageSingleField()
|
public function testCustomMessageSingleField()
|
||||||
@ -100,8 +96,6 @@ class MapRulesTest extends BaseTestCase
|
|||||||
$errors1 = $v->errors('myField1');
|
$errors1 = $v->errors('myField1');
|
||||||
$this->assertEquals('My Custom Error 1', $errors1[0]);
|
$this->assertEquals('My Custom Error 1', $errors1[0]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$errors2 = $v->errors('myField2');
|
$errors2 = $v->errors('myField2');
|
||||||
$this->assertEquals('My Custom Error 2', $errors2[0]);
|
$this->assertEquals('My Custom Error 2', $errors2[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Valitron\Validator;
|
use Valitron\Validator;
|
||||||
|
|
||||||
|
class StopOnFirstFail extends BaseTestCase
|
||||||
class StopOnFirstFail extends BaseTestCase {
|
{
|
||||||
|
public function testStopOnFirstFail()
|
||||||
public function testStopOnFirstFail() {
|
{
|
||||||
$rules = array(
|
$rules = array(
|
||||||
'myField1' => array(
|
'myField1' => array(
|
||||||
array('lengthMin', 5, 'message' => 'myField1 must be 5 characters minimum'),
|
array('lengthMin', 5, 'message' => 'myField1 must be 5 characters minimum'),
|
||||||
@ -24,5 +25,4 @@ class StopOnFirstFail extends BaseTestCase {
|
|||||||
$errors = $v->errors();
|
$errors = $v->errors();
|
||||||
$this->assertCount(1, $errors['myField1']);
|
$this->assertCount(1, $errors['myField1']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1302,7 +1302,7 @@ class ValidateTest extends BaseTestCase
|
|||||||
|
|
||||||
public function testFalseStillTriggersValidation()
|
public function testFalseStillTriggersValidation()
|
||||||
{
|
{
|
||||||
$v = new Validator(array('test' => FALSE));
|
$v = new Validator(array('test' => false));
|
||||||
$v->rule('min', 'test', 5);
|
$v->rule('min', 'test', 5);
|
||||||
$this->assertFalse($v->validate());
|
$this->assertFalse($v->validate());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user