Browse Source

another batch of revese changes

Paweł Kukiełka 10 years ago
parent
commit
27f52f2dbe
2 changed files with 45 additions and 64 deletions
  1. 3 6
      src/Validation/Validator.php
  2. 42 58
      tests/TestCase/Validation/ValidatorTest.php

+ 3 - 6
src/Validation/Validator.php

@@ -158,7 +158,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
             $set = $set ?: new ValidationSet;
             $this->_fields[$name] = $set;
         }
-
         return $this->_fields[$name];
     }
 
@@ -318,6 +317,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
         foreach ($rules as $name => $rule) {
             $field->add($name, $rule);
         }
+
         return $this;
     }
 
@@ -349,7 +349,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
                 $validator->provider($provider, $this->provider($provider));
             }
             $errors = $validator->errors($value, $context['newRecord']);
-
             return empty($errors) ? true : $errors;
         }]);
         return $this;
@@ -392,7 +391,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
                     $errors[$i] = $check;
                 }
             }
-
             return empty($errors) ? true : $errors;
         }]);
         return $this;
@@ -1444,7 +1442,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
     public function hasAtLeast($field, $count, $message = null, $when = null)
     {
         $extra = array_filter(['on' => $when, 'message' => $message]);
-
         return $this->add($field, 'hasAtLeast', $extra + [
             'rule' => function ($value) use ($count) {
                 if (is_array($value) && isset($value['_ids'])) {
@@ -1470,7 +1467,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
     public function hasAtMost($field, $count, $message = null, $when = null)
     {
         $extra = array_filter(['on' => $when, 'message' => $message]);
-
         return $this->add($field, 'hasAtMost', $extra + [
             'rule' => function ($value) use ($count) {
                 if (is_array($value) && isset($value['_ids'])) {
@@ -1536,6 +1532,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
                 ($required === 'update' && $newRecord)
             );
         }
+
         return !$required;
     }
 
@@ -1561,6 +1558,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
                 ($allowed === 'update' && !$newRecord)
             );
         }
+
         return $allowed;
     }
 
@@ -1578,7 +1576,6 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
         $isArray = is_array($data);
         if ($isArray && (isset($data['year']) || isset($data['hour']))) {
             $value = implode('', $data);
-
             return strlen($value) === 0;
         }
         if ($isArray && isset($data['name'], $data['type'], $data['tmp_name'], $data['error'])) {

+ 42 - 58
tests/TestCase/Validation/ValidatorTest.php

@@ -203,18 +203,15 @@ class ValidatorTest extends TestCase
         $this->assertTrue($validator->field('title')->isPresenceRequired());
         $this->assertTrue($validator->field('created')->isPresenceRequired());
 
-        $validator->requirePresence(
-            [
-                'title' => [
-                    'mode' => false
-                ],
-                'content' => [
-                    'mode' => 'update'
-                ],
-                'subject'
+        $validator->requirePresence([
+            'title' => [
+                'mode' => false
             ],
-            true
-        );
+            'content' => [
+                'mode' => 'update'
+            ],
+            'subject'
+        ], true);
         $this->assertFalse($validator->field('title')->isPresenceRequired());
         $this->assertEquals('update', $validator->field('content')->isPresenceRequired());
         $this->assertTrue($validator->field('subject')->isPresenceRequired());
@@ -561,22 +558,19 @@ class ValidatorTest extends TestCase
     {
         $validator = new Validator;
 
-        $validator->allowEmpty(
-            [
-                'title',
-                'subject',
-                'posted_at' => [
-                    'when' => false
-                ],
-                'updated_at' => [
-                    'when' => true
-                ],
-                'show_at' => [
-                    'when' => 'update'
-                ]
+        $validator->allowEmpty([
+            'title',
+            'subject',
+            'posted_at' => [
+                'when' => false
             ],
-            'create'
-        );
+            'updated_at' => [
+                'when' => true
+            ],
+            'show_at' => [
+                'when' => 'update'
+            ]
+        ], 'create');
         $this->assertEquals('create', $validator->field('title')->isEmptyAllowed());
         $this->assertEquals('create', $validator->field('subject')->isEmptyAllowed());
         $this->assertFalse($validator->field('posted_at')->isEmptyAllowed());
@@ -623,26 +617,22 @@ class ValidatorTest extends TestCase
         $this->assertFalse($validator->field('title')->isEmptyAllowed());
         $this->assertFalse($validator->field('created')->isEmptyAllowed());
 
-        $validator->notEmpty(
-            [
-                'title' => [
-                    'when' => false
-                ],
-                'content' => [
-                    'when' => 'update'
-                ],
-                'posted_at' => [
-                    'when' => 'create'
-                ],
-                'show_at' => [
-                    'message' => 'Show date cannot be empty',
-                    'when' => false
-                ],
-                'subject'
+        $validator->notEmpty([
+            'title' => [
+                'when' => false
             ],
-            'Not empty',
-            true
-        );
+            'content' => [
+                'when' => 'update'
+            ],
+            'posted_at' => [
+                'when' => 'create'
+            ],
+            'show_at' => [
+                'message' => 'Show date cannot be empty',
+                'when' => false
+            ],
+            'subject'
+        ], 'Not empty', true);
 
         $this->assertFalse($validator->field('title')->isEmptyAllowed());
         $this->assertTrue($validator->isEmptyAllowed('content', true));
@@ -651,16 +641,13 @@ class ValidatorTest extends TestCase
         $this->assertTrue($validator->isEmptyAllowed('posted_at', false));
         $this->assertTrue($validator->field('subject')->isEmptyAllowed());
 
-        $errors = $validator->errors(
-            [
-                'title' => '',
-                'content' => '',
-                'posted_at' => null,
-                'show_at' => null,
-                'subject' => ''
-            ],
-            false
-        );
+        $errors = $validator->errors([
+            'title' => '',
+            'content' => '',
+            'posted_at' => null,
+            'show_at' => null,
+            'subject' => ''
+        ], false);
 
         $expected = [
             'title' => ['_empty' => 'Not empty'],
@@ -948,7 +935,6 @@ class ValidatorTest extends TestCase
                     'field' => 'title'
                 ];
                 $this->assertEquals($expected, $context);
-
                 return "That ain't cool, yo";
             }));
 
@@ -994,7 +980,6 @@ class ValidatorTest extends TestCase
                     'field' => 'title'
                 ];
                 $this->assertEquals($expected, $context);
-
                 return "That ain't cool, yo";
             }));
         $validator->provider('thing', $thing);
@@ -1016,7 +1001,6 @@ class ValidatorTest extends TestCase
         $validator->add('name', 'myRule', [
             'rule' => function ($data, $provider) {
                 $this->assertEquals('foo', $data);
-
                 return 'You fail';
             }
         ]);