Tests code style fixes

This commit is contained in:
misantron 2018-09-22 17:00:34 +03:00
parent f70e27af56
commit c52612f86c
8 changed files with 59 additions and 55 deletions

View File

@ -897,7 +897,14 @@ class Validator
return $isInstanceOf;
}
//Validate optional field
/**
* Validate optional field
*
* @param $field
* @param $value
* @param $params
* @return bool
*/
protected function validateOptional($field, $value, $params)
{
//Always return true
@ -997,7 +1004,7 @@ class Validator
}
// Catches the case where the data isn't an array or object
if (is_scalar($data)) {
return array(NULL, false);
return array(null, false);
}
$identifier = array_shift($identifiers);
// Glob match
@ -1012,8 +1019,7 @@ class Validator
}
}
return array($values, true);
}
// Dead end, abort
} // Dead end, abort
elseif ($identifier === null || ! isset($data[$identifier])) {
if ($allow_empty){
//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;

View File

@ -18,7 +18,7 @@ class BaseTestCase extends TestCase
protected function resetProperty($name, $value = null)
{
$prop = new ReflectionProperty('Valitron\Validator', $name);
$prop = new \ReflectionProperty('Valitron\Validator', $name);
$prop->setAccessible(true);
$prop->setValue($value);
$prop->setAccessible(false);

View File

@ -1,4 +1,5 @@
<?php
use Valitron\Validator;
class ErrorMessagesTest extends BaseTestCase
@ -66,7 +67,8 @@ class ErrorMessagesTest extends BaseTestCase
$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->rule('required', 'name')->label('my name');
$v->validate();

View File

@ -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()
{
@ -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()
{

View File

@ -1,12 +1,11 @@
<?php
use Valitron\Validator;
use Valitron\Validator;
class MapRulesTest extends BaseTestCase
{
public function testMapSingleFieldRules()
{
$rules = array(
'required',
array('lengthMin', 4)
@ -24,7 +23,6 @@ class MapRulesTest extends BaseTestCase
public function testSingleFieldDot()
{
$v = new Valitron\Validator(array(
'settings' => array(
array('threshold' => 50),
@ -36,7 +34,6 @@ class MapRulesTest extends BaseTestCase
));
$this->assertFalse($v->validate());
}
public function testMapMultipleFieldsRules()
@ -60,7 +57,6 @@ class MapRulesTest extends BaseTestCase
$this->assertFalse($v->validate());
$this->assertFalse($v->errors('myField1'));
$this->assertEquals(2, sizeof($v->errors('myField2')));
}
public function testCustomMessageSingleField()
@ -100,8 +96,6 @@ class MapRulesTest extends BaseTestCase
$errors1 = $v->errors('myField1');
$this->assertEquals('My Custom Error 1', $errors1[0]);
$errors2 = $v->errors('myField2');
$this->assertEquals('My Custom Error 2', $errors2[0]);
}

View File

@ -1,10 +1,11 @@
<?php
use Valitron\Validator;
class StopOnFirstFail extends BaseTestCase {
public function testStopOnFirstFail() {
class StopOnFirstFail extends BaseTestCase
{
public function testStopOnFirstFail()
{
$rules = array(
'myField1' => array(
array('lengthMin', 5, 'message' => 'myField1 must be 5 characters minimum'),
@ -24,5 +25,4 @@ class StopOnFirstFail extends BaseTestCase {
$errors = $v->errors();
$this->assertCount(1, $errors['myField1']);
}
}

View File

@ -1302,7 +1302,7 @@ class ValidateTest extends BaseTestCase
public function testFalseStillTriggersValidation()
{
$v = new Validator(array('test' => FALSE));
$v = new Validator(array('test' => false));
$v->rule('min', 'test', 5);
$this->assertFalse($v->validate());
}