Completed
Push — master ( 9bb1a7...9f8480 )
by Helmut
06:35
created
src/Form.php 3 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      */
358 358
     public function completed($name = null)
359 359
     {
360
-        if($this->submitted($name) && $this->valid()) {
360
+        if ($this->submitted($name) && $this->valid()) {
361 361
             $this->broadcast('completed');
362 362
             return true;
363 363
         }
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
         $errors = [];
498 498
 
499 499
         foreach ($this->fields as $field) {
500
-            foreach($field->errors() as $error) {
500
+            foreach ($field->errors() as $error) {
501 501
                 $errors[] = $error;
502 502
             }
503 503
         }
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
     {
620 620
         $config = $this->templateConfig($template);
621 621
 
622
-        if ( isset($config['plugins']) && is_array($config['plugins'])) {
623
-            foreach($config['plugins'] as $plugin) {
622
+        if (isset($config['plugins']) && is_array($config['plugins'])) {
623
+            foreach ($config['plugins'] as $plugin) {
624 624
                 $this->addPlugin($plugin);
625 625
             }
626 626
         }
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
     {
637 637
         $config = $this->templateConfig($template);
638 638
 
639
-        if ( isset($config['plugins']) && is_array($config['plugins'])) {
640
-            foreach($config['plugins'] as $plugin) {
639
+        if (isset($config['plugins']) && is_array($config['plugins'])) {
640
+            foreach ($config['plugins'] as $plugin) {
641 641
                 $this->removePlugin($plugin);
642 642
             }
643 643
         }
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             foreach ($field->errors() as $error => $parameters) {
675 675
 
676 676
                 if ($error == 'userDefined') {
677
-                    foreach($parameters as $message) {
677
+                    foreach ($parameters as $message) {
678 678
                         $properties['errors'][] = ['error' => $message];
679 679
                     }
680 680
                 } else {
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 
684 684
                     $message = $this->translate($error, $field);
685 685
 
686
-                    foreach($parameters as $key => $value) {
686
+                    foreach ($parameters as $key => $value) {
687 687
                         if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value;
688 688
                         if (is_array($value)) $value = implode(', ', $value);
689 689
                         $message = str_replace('['.$key.']', $value, $message);
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
      */
931 931
     private function broadcast($event, $params = []) 
932 932
     {
933
-        foreach($this->plugins as $plugin) {
933
+        foreach ($this->plugins as $plugin) {
934 934
             $plugin->event($this, $event, $params);
935 935
         }
936 936
     }
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
     {
1079 1079
         if ( ! method_exists($this, $method))
1080 1080
         {
1081
-            if ( $this->typeExists($method)) {
1081
+            if ($this->typeExists($method)) {
1082 1082
                 return $this->addField($method, array_shift($parameters));
1083 1083
             }
1084 1084
         }
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -259,7 +259,9 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public function fields($names = null)
261 261
     {
262
-        if (is_null($names)) return $this->fields;
262
+        if (is_null($names)) {
263
+            return $this->fields;
264
+        }
263 265
 
264 266
         return array_filter($this->fields, function($field) use ($names) {
265 267
             return array_key_exists($field->name, $names);
@@ -442,7 +444,9 @@  discard block
 block discarded – undo
442 444
      */
443 445
     public function addNamespaceForClass($class)
444 446
     {
445
-        if (is_object($class)) $class = get_class($class);
447
+        if (is_object($class)) {
448
+            $class = get_class($class);
449
+        }
446 450
 
447 451
         $reflector = new \ReflectionClass($class);
448 452
 
@@ -477,7 +481,9 @@  discard block
 block discarded – undo
477 481
         $class = '\\Fields\\'.ucwords($class).'\\'.ucwords($class);
478 482
 
479 483
         foreach ($this->namespaces as $namespace) {
480
-            if (class_exists($namespace.$class)) return $namespace.$class;
484
+            if (class_exists($namespace.$class)) {
485
+                return $namespace.$class;
486
+            }
481 487
         }
482 488
     }
483 489
 
@@ -490,9 +496,13 @@  discard block
 block discarded – undo
490 496
      */
491 497
     public function errors($name = null)
492 498
     {
493
-        if ($this->submitted()) $this->validate();
499
+        if ($this->submitted()) {
500
+            $this->validate();
501
+        }
494 502
 
495
-        if ( ! is_null($name)) $this->field($name)->errors();
503
+        if ( ! is_null($name)) {
504
+            $this->field($name)->errors();
505
+        }
496 506
 
497 507
         $errors = [];
498 508
 
@@ -684,8 +694,12 @@  discard block
 block discarded – undo
684 694
                     $message = $this->translate($error, $field);
685 695
 
686 696
                     foreach($parameters as $key => $value) {
687
-                        if (is_object($value) && method_exists($value, '__toString')) $value = (string) $value;
688
-                        if (is_array($value)) $value = implode(', ', $value);
697
+                        if (is_object($value) && method_exists($value, '__toString')) {
698
+                            $value = (string) $value;
699
+                        }
700
+                        if (is_array($value)) {
701
+                            $value = implode(', ', $value);
702
+                        }
689 703
                         $message = str_replace('['.$key.']', $value, $message);
690 704
                     }
691 705
                     $properties['errors'][] = ['error' => $message];
@@ -705,7 +719,9 @@  discard block
 block discarded – undo
705 719
      */
706 720
     public function renderField($field, $properties = null) 
707 721
     {   
708
-        if (is_null($properties)) $properties = $this->fieldProperties($field);
722
+        if (is_null($properties)) {
723
+            $properties = $this->fieldProperties($field);
724
+        }
709 725
 
710 726
         return $this->renderTemplate($field->type, $properties, $field);
711 727
     }
@@ -719,7 +735,9 @@  discard block
 block discarded – undo
719 735
      */
720 736
     public function renderFieldErrors($field, $properties = null) 
721 737
     {   
722
-        if (is_null($properties)) $properties = $this->fieldProperties($field);
738
+        if (is_null($properties)) {
739
+            $properties = $this->fieldProperties($field);
740
+        }
723 741
 
724 742
         return $this->renderTemplate('errors', $properties, $field);
725 743
     }   
@@ -736,9 +754,13 @@  discard block
 block discarded – undo
736 754
 
737 755
         $this->setValues();
738 756
 
739
-        if ($this->submitted()) $this->validate();
757
+        if ($this->submitted()) {
758
+            $this->validate();
759
+        }
740 760
 
741
-        if ( ! is_null($template)) $this->setTemplate($template);
761
+        if ( ! is_null($template)) {
762
+            $this->setTemplate($template);
763
+        }
742 764
 
743 765
         $properties = [];
744 766
         $properties['id'] = $this->id;
@@ -992,7 +1014,9 @@  discard block
 block discarded – undo
992 1014
      */
993 1015
     public function pathForClass($class)
994 1016
     {
995
-        if (is_object($class)) $class = get_class($class);
1017
+        if (is_object($class)) {
1018
+            $class = get_class($class);
1019
+        }
996 1020
 
997 1021
         $reflector = new \ReflectionClass($class);
998 1022
         $path = dirname($reflector->getFileName()); 
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
     /**
333 333
      * Fill a model with values.
334 334
      *
335
-     * @param  object  $model
335
+     * @param  \stdClass  $model
336 336
      * @param  array  $names
337 337
      */
338 338
     public function fill($model, $names = null)
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      * Check if a type exists.
456 456
      *
457 457
      * @param  string  $type
458
-     * @return string
458
+     * @return boolean
459 459
      */
460 460
     public function typeExists($type)
461 461
     {
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
      *
1071 1071
      * @param  string  $method
1072 1072
      * @param  array  $parameters
1073
-     * @return mixed
1073
+     * @return Fields\Field|null
1074 1074
      */
1075 1075
     public function __call($method, $parameters)
1076 1076
     {
Please login to merge, or discard this patch.
src/Request.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,26 +4,26 @@
 block discarded – undo
4 4
 
5 5
 interface Request {
6 6
 	
7
-	/**
7
+    /**
8 8
      * Fetch all values from the request.
9 9
      *
10 10
      * @return array
11 11
      */
12
-	public function all();
12
+    public function all();
13 13
 
14
-	/**
14
+    /**
15 15
      * Fetch a value from the request matching provided key.
16 16
      *
17 17
      * @var string
18 18
      * @return mixed
19 19
      */
20
-	public function get($key);
20
+    public function get($key);
21 21
 
22
-	/**
22
+    /**
23 23
      * Return array of csrf template properties.
24 24
      *
25 25
      * @return array
26 26
      */
27
-	public function csrf();	
27
+    public function csrf();	
28 28
 
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.
tests/codeception/_support/_generated/AcceptanceTesterActions.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 // @codingStandardsIgnoreFile
7 7
 
8 8
 use Codeception\Module\PhpBrowser;
9
-use Helper\Acceptance;
10 9
 
11 10
 trait AcceptanceTesterActions
12 11
 {
Please login to merge, or discard this patch.
tests/codeception/_support/_generated/FunctionalTesterActions.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 // @codingStandardsIgnoreFile
7 7
 
8 8
 use Codeception\Module\PhpBrowser;
9
-use Helper\Functional;
10 9
 
11 10
 trait FunctionalTesterActions
12 11
 {
Please login to merge, or discard this patch.
tests/codeception/_support/_generated/UnitTesterActions.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 // @codingStandardsIgnoreFile
7 7
 
8 8
 use Codeception\Module\Asserts;
9
-use Helper\Unit;
10 9
 
11 10
 trait UnitTesterActions
12 11
 {
Please login to merge, or discard this patch.
tests/unit/FormTest.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@
 block discarded – undo
2 2
 
3 3
 namespace Helmut\Forms\Testing;
4 4
 
5
-use Helmut\Forms\Testing\Stubs\FormWithDefinition;
6
-use Helmut\Forms\Testing\Stubs\Custom\FormWithCustomNamespace;
7 5
 use Helmut\Forms\Testing\Stubs\CustomExtension\FormWithCustomExtension;
6
+use Helmut\Forms\Testing\Stubs\Custom\FormWithCustomNamespace;
7
+use Helmut\Forms\Testing\Stubs\FormWithDefinition;
8 8
 
9 9
 class FormTest extends FormTestCase {
10 10
 	
Please login to merge, or discard this patch.
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -8,467 +8,467 @@
 block discarded – undo
8 8
 
9 9
 class FormTest extends FormTestCase {
10 10
 	
11
-	/** @test */
11
+    /** @test */
12 12
     public function it_can_be_created()
13 13
     {
14
-    	$this->assertEquals(get_class($this->form()), 'Helmut\Forms\Testing\Stubs\Form');
15
-    	$this->assertEquals(get_parent_class($this->form()), 'Helmut\Forms\Form');
14
+        $this->assertEquals(get_class($this->form()), 'Helmut\Forms\Testing\Stubs\Form');
15
+        $this->assertEquals(get_parent_class($this->form()), 'Helmut\Forms\Form');
16 16
     }
17 17
 
18
-	/** @test */
19
-	public function it_can_be_rendered()
20
-	{
21
-		$form = $this->form();
18
+    /** @test */
19
+    public function it_can_be_rendered()
20
+    {
21
+        $form = $this->form();
22 22
 		
23
-		$this->assertContains('<form', $form->render());
24
-	}	    
23
+        $this->assertContains('<form', $form->render());
24
+    }	    
25 25
 
26
-	/** @test */
26
+    /** @test */
27 27
     public function it_can_create_a_field()
28 28
     {
29
-    	$form = $this->form();
30
-		$field = $form->text('foo');
29
+        $form = $this->form();
30
+        $field = $form->text('foo');
31 31
 
32
-    	$this->assertTrue(is_subclass_of($field, 'Helmut\Forms\Field'));
32
+        $this->assertTrue(is_subclass_of($field, 'Helmut\Forms\Field'));
33 33
     } 
34 34
 
35
- 	/** @test */
35
+        /** @test */
36 36
     public function it_can_have_fields_defined()
37 37
     {
38
-    	$form = new FormWithDefinition($this->request());
39
-    	$form->removeAllPlugins();
38
+        $form = new FormWithDefinition($this->request());
39
+        $form->removeAllPlugins();
40 40
 
41
-		$fields = $form->fields();
41
+        $fields = $form->fields();
42 42
 		
43
-		$this->assertCount(1, $form->fields());
43
+        $this->assertCount(1, $form->fields());
44 44
     }  
45 45
 
46
-     /** @test */
46
+        /** @test */
47 47
     public function it_wont_create_the_same_field_twice()
48 48
     {
49
-    	$form = $this->form();
50
-		$field1 = $form->text('foo');
51
-		$field2 = $form->text('foo');
49
+        $form = $this->form();
50
+        $field1 = $form->text('foo');
51
+        $field2 = $form->text('foo');
52 52
 
53
-		$this->assertCount(1, $form->fields());
54
-		$this->assertSame($field1, $field2);
53
+        $this->assertCount(1, $form->fields());
54
+        $this->assertSame($field1, $field2);
55 55
     }
56 56
 
57
-	/** @test */
57
+    /** @test */
58 58
     public function it_fetches_all_the_keys()
59 59
     {
60
-    	$form = $this->form();
61
-		$form->text('foo');
62
-		$form->name('bar');
63
-		$form->email('baz');
60
+        $form = $this->form();
61
+        $form->text('foo');
62
+        $form->name('bar');
63
+        $form->email('baz');
64 64
 
65
-		$expected = ['foo', 'bar_first', 'bar_surname', 'bar', 'baz'];
66
-		$this->assertSame($expected, $form->keys());
67
-	} 
65
+        $expected = ['foo', 'bar_first', 'bar_surname', 'bar', 'baz'];
66
+        $this->assertSame($expected, $form->keys());
67
+    } 
68 68
 
69
-	/** @test */
69
+    /** @test */
70 70
     public function it_fetches_all_values()
71 71
     {
72
-    	$form = $this->form();
73
-		$form->text('foo');
74
-		$form->name('bar');
75
-		$form->email('baz');
72
+        $form = $this->form();
73
+        $form->text('foo');
74
+        $form->name('bar');
75
+        $form->email('baz');
76 76
 
77
-		$expected = ['foo'=>'', 'bar_first'=>'', 'bar_surname'=>'', 'bar'=>'', 'baz'=>''];
78
-		$this->assertSame($expected, $form->all());
79
-	}   
77
+        $expected = ['foo'=>'', 'bar_first'=>'', 'bar_surname'=>'', 'bar'=>'', 'baz'=>''];
78
+        $this->assertSame($expected, $form->all());
79
+    }   
80 80
 
81
-	/** @test */
81
+    /** @test */
82 82
     public function it_fetches_values_for_simple_field()
83 83
     {
84
-    	$form = $this->form();
85
-		$form->text('foo');
84
+        $form = $this->form();
85
+        $form->text('foo');
86 86
 
87
-		$this->assertSame($form->get('foo'), '');
88
-	}	 
87
+        $this->assertSame($form->get('foo'), '');
88
+    }	 
89 89
 
90
-	/** @test */
90
+    /** @test */
91 91
     public function it_fetches_values_for_a_complex_field()
92 92
     {
93
-    	$form = $this->form();
94
-		$form->name('foo');
93
+        $form = $this->form();
94
+        $form->name('foo');
95 95
 
96
-		$expected = ['foo_first'=>'', 'foo_surname'=>'', 'foo'=>''];
97
-		$this->assertSame($form->get('foo'), $expected);
98
-	}
96
+        $expected = ['foo_first'=>'', 'foo_surname'=>'', 'foo'=>''];
97
+        $this->assertSame($form->get('foo'), $expected);
98
+    }
99 99
 
100
-	/** @test */
100
+    /** @test */
101 101
     public function it_fetches_values_for_a_complex_field_by_key()
102 102
     {
103
-    	$form = $this->form();
104
-		$form->name('foo');
103
+        $form = $this->form();
104
+        $form->name('foo');
105 105
 
106
-		$this->assertSame($form->get('foo', 'surname'), '');
107
-	}
106
+        $this->assertSame($form->get('foo', 'surname'), '');
107
+    }
108 108
 
109
-	/** @test */
109
+    /** @test */
110 110
     public function it_is_not_submitted_by_default()
111 111
     {
112
-    	$request = $this->request();
113
-    	$request->method('get')->will($this->returnValueMap([
114
-    			['foo', false],
115
-    		])
116
-    	);
112
+        $request = $this->request();
113
+        $request->method('get')->will($this->returnValueMap([
114
+                ['foo', false],
115
+            ])
116
+        );
117 117
 
118
-    	$form = $this->form($request);
119
-    	$form->button('foo');
118
+        $form = $this->form($request);
119
+        $form->button('foo');
120 120
 
121
-		$this->assertFalse($form->submitted());
122
-	}	
121
+        $this->assertFalse($form->submitted());
122
+    }	
123 123
 
124
-	/** @test */
124
+    /** @test */
125 125
     public function it_can_be_submitted()
126 126
     {
127
-		$request = $this->request();
128
-    	$request->method('get')->will($this->returnValueMap([
129
-    			['foo', true],
130
-    		])
131
-    	);
127
+        $request = $this->request();
128
+        $request->method('get')->will($this->returnValueMap([
129
+                ['foo', true],
130
+            ])
131
+        );
132 132
 
133
-    	$form = $this->form($request);
134
-    	$form->button('foo');
133
+        $form = $this->form($request);
134
+        $form->button('foo');
135 135
 
136
-		$this->assertTrue($form->submitted());
137
-	}
136
+        $this->assertTrue($form->submitted());
137
+    }
138 138
 
139
-	/** @test */
139
+    /** @test */
140 140
     public function it_can_detect_which_submit_button_was_clicked()
141 141
     {
142
-    	$request = $this->request();
143
-    	$request->method('get')->will($this->returnValueMap([
144
-    			['foo', null],
145
-    			['bar', true],
146
-    		])
147
-    	);
142
+        $request = $this->request();
143
+        $request->method('get')->will($this->returnValueMap([
144
+                ['foo', null],
145
+                ['bar', true],
146
+            ])
147
+        );
148
+
149
+        $form = $this->form($request);
150
+        $form->button('foo');
151
+        $form->button('bar');
152
+
153
+        $this->assertFalse($form->submitted('foo'));
154
+        $this->assertTrue($form->submitted('bar'));
155
+    }	
156
+
157
+    /** @test */
158
+    public function it_loads_values_from_the_request()
159
+    {
160
+        $request = $this->request();
161
+        $request->method('all')->will($this->returnValue(['foo'=>'bar', 'register'=>true]));
162
+        $request->method('get')->will($this->returnValueMap([
163
+            ['foo', 'bar'],
164
+            ['register', true],
165
+        ]));
148 166
 
149
-    	$form = $this->form($request);
150
-    	$form->button('foo');
151
-    	$form->button('bar');
167
+        $form = $this->form($request);
168
+        $form->text('foo');
169
+        $form->button('register');
152 170
 
153
-		$this->assertFalse($form->submitted('foo'));
154
-		$this->assertTrue($form->submitted('bar'));
155
-	}	
171
+        $this->assertSame($form->get('foo'), 'bar');
172
+    }	
156 173
 
157
-	/** @test */
158
-    public function it_loads_values_from_the_request()
174
+    /** @test */
175
+    public function it_loads_complex_values_from_the_request()
176
+    {
177
+        $request = $this->request();
178
+        $request->method('all')->will($this->returnValue(['foo_first'=>'John', 'foo_surname'=>'Smith', 'register'=>true]));
179
+        $request->method('get')->will($this->returnValueMap([
180
+            ['foo_first', 'John'],
181
+            ['foo_surname', 'Smith'],
182
+            ['register', true],
183
+        ]));
184
+
185
+        $form = $this->form($request);		
186
+        $form->name('foo');
187
+        $form->button('register');
188
+
189
+        $expected = ['foo_first'=>'John', 'foo_surname'=>'Smith', 'foo'=>'John Smith'];
190
+        $this->assertSame($form->get('foo'), $expected);
191
+    }
192
+
193
+    /** @test */
194
+    public function it_loads_complex_values_by_key_from_the_request()
195
+    {
196
+        $request = $this->request();
197
+        $request->method('all')->will($this->returnValue(['foo_first'=>'John', 'foo_surname'=>'Smith', 'register'=>true]));
198
+        $request->method('get')->will($this->returnValueMap([
199
+            ['foo_first', 'John'],
200
+            ['foo_surname', 'Smith'],
201
+            ['register', true],
202
+        ]));
203
+
204
+        $form = $this->form($request);		
205
+        $form->name('foo');
206
+        $form->button('register');
207
+
208
+        $this->assertSame($form->get('foo', 'surname'), 'Smith');
209
+    }	
210
+
211
+    /** @test */
212
+    public function it_only_loads_values_if_submitted()
159 213
     {
160
-    	$request = $this->request();
161
-    	$request->method('all')->will($this->returnValue(['foo'=>'bar', 'register'=>true]));
162
-    	$request->method('get')->will($this->returnValueMap([
163
-    		['foo', 'bar'],
164
-    		['register', true],
165
-    	]));
214
+        $request = $this->request();
215
+        $request->method('all')->will($this->returnValue(['foo'=>'bar', 'register'=>null]));
216
+        $request->method('get')->will($this->returnValueMap([
217
+            ['foo', 'bar'],
218
+            ['register', null],
219
+        ]));
166 220
 
167
-		$form = $this->form($request);
168
-		$form->text('foo');
169
-		$form->button('register');
221
+        $form = $this->form($request);		
222
+        $form->text('foo');
223
+        $form->button('register');
170 224
 
171
-		$this->assertSame($form->get('foo'), 'bar');
172
-	}	
225
+        $this->assertSame($form->get('foo'), '');
226
+    }	
173 227
 
174
-	/** @test */
175
-    public function it_loads_complex_values_from_the_request()
228
+    /** @test */
229
+    public function it_is_valid_by_default()
176 230
     {
177
-		$request = $this->request();
178
-    	$request->method('all')->will($this->returnValue(['foo_first'=>'John', 'foo_surname'=>'Smith', 'register'=>true]));
179
-    	$request->method('get')->will($this->returnValueMap([
180
-    		['foo_first', 'John'],
181
-    		['foo_surname', 'Smith'],
182
-    		['register', true],
183
-    	]));
231
+        $form = $this->form();		
232
+        $form->text('foo');
233
+        $form->button('register');
184 234
 
185
-		$form = $this->form($request);		
186
-		$form->name('foo');
187
-		$form->button('register');
235
+        $this->assertTrue($form->valid());
236
+    }	
188 237
 
189
-		$expected = ['foo_first'=>'John', 'foo_surname'=>'Smith', 'foo'=>'John Smith'];
190
-		$this->assertSame($form->get('foo'), $expected);
191
-	}
238
+    /** @test */
239
+    public function it_can_validate_specific_fields()
240
+    {
241
+        $form = $this->form();		
242
+        $form->email('foo')->default('[email protected]');
243
+        $form->email('bar')->default('bar@invalid');
244
+        $form->button('register');
192 245
 
193
-	/** @test */
194
-    public function it_loads_complex_values_by_key_from_the_request()
246
+        $this->assertTrue($form->valid('foo'));
247
+        $this->assertFalse($form->valid('bar'));
248
+    }
249
+
250
+    /** @test */
251
+    public function it_renders_no_errors_unless_submitted()
195 252
     {
196
-		$request = $this->request();
197
-    	$request->method('all')->will($this->returnValue(['foo_first'=>'John', 'foo_surname'=>'Smith', 'register'=>true]));
198
-    	$request->method('get')->will($this->returnValueMap([
199
-    		['foo_first', 'John'],
200
-    		['foo_surname', 'Smith'],
201
-    		['register', true],
202
-    	]));
253
+        $form = $this->form();
254
+        $form->text('foo')->required();
255
+        $form->button('register');
256
+		
257
+        $this->assertNotContains('<p class="error_message"', $form->render());
258
+    }
259
+
260
+    /** @test */
261
+    public function it_renders_errors()
262
+    {
263
+        $request = $this->request();
264
+        $request->method('get')->will($this->returnValueMap([
265
+            ['foo', ''],
266
+            ['register', true],
267
+        ]));
203 268
 
204
-		$form = $this->form($request);		
205
-		$form->name('foo');
206
-		$form->button('register');
269
+        $form = $this->form($request);
270
+        $form->text('foo')->required();
271
+        $form->button('register');
207 272
 
208
-		$this->assertSame($form->get('foo', 'surname'), 'Smith');
209
-	}	
273
+        $this->assertContains('<p class="error_message">', $form->render());
274
+    }
210 275
 
211
-	/** @test */
212
-    public function it_only_loads_values_if_submitted()
276
+    /** @test */
277
+    public function it_renders_default_language()
213 278
     {
214
-		$request = $this->request();
215
-    	$request->method('all')->will($this->returnValue(['foo'=>'bar', 'register'=>null]));
216
-    	$request->method('get')->will($this->returnValueMap([
217
-    		['foo', 'bar'],
218
-    		['register', null],
219
-    	]));
279
+        $form = $this->form();
280
+        $form->text('foo')->required();
281
+        $form->button('register');
220 282
 
221
-		$form = $this->form($request);		
222
-		$form->text('foo');
223
-		$form->button('register');
283
+        $this->assertContains('This field is required.', $form->render());
284
+    }
224 285
 
225
-		$this->assertSame($form->get('foo'), '');
226
-	}	
286
+    /** @test */
287
+    public function it_renders_default_added_language()
288
+    {
289
+        $form = $this->form();
290
+        $form->setLanguage('es');
291
+        $form->text('foo')->required();
227 292
 
228
-	/** @test */
229
-    public function it_is_valid_by_default()
293
+        $this->assertContains('Este campo es obligatorio.', $form->render());
294
+    }	
295
+
296
+    /** @test */
297
+    public function it_sets_own_namespace()
298
+    {	
299
+        $form = $this->form();
300
+
301
+        $this->assertSame($form->namespaces(), ['Helmut\Forms\Testing\Stubs', 'Helmut\Forms']);
302
+    }
303
+
304
+    /** @test */
305
+    public function it_can_add_a_namespace()
230 306
     {
231
-		$form = $this->form();		
232
-		$form->text('foo');
233
-		$form->button('register');
307
+        $form = $this->form();
308
+        $form->addNamespace('My\Custom\Namespace');
309
+        $form->addNamespace('My\Other\Custom\Namespace');
234 310
 
235
-		$this->assertTrue($form->valid());
236
-	}	
311
+        $this->assertSame($form->namespaces(), ['My\Other\Custom\Namespace', 'My\Custom\Namespace', 'Helmut\Forms\Testing\Stubs', 'Helmut\Forms']);
312
+    }
237 313
 
238
-	/** @test */
239
-    public function it_can_validate_specific_fields()
314
+    /** @test */
315
+    public function it_can_add_autoload_paths()
240 316
     {
241
-		$form = $this->form();		
242
-		$form->email('foo')->default('[email protected]');
243
-		$form->email('bar')->default('bar@invalid');
244
-		$form->button('register');
245
-
246
-		$this->assertTrue($form->valid('foo'));
247
-		$this->assertFalse($form->valid('bar'));
248
-	}
249
-
250
-	/** @test */
251
-	public function it_renders_no_errors_unless_submitted()
252
-	{
253
-		$form = $this->form();
254
-		$form->text('foo')->required();
255
-		$form->button('register');
256
-		
257
-		$this->assertNotContains('<p class="error_message"', $form->render());
258
-	}
259
-
260
-	/** @test */
261
-	public function it_renders_errors()
262
-	{
263
-		$request = $this->request();
264
-    	$request->method('get')->will($this->returnValueMap([
265
-    		['foo', ''],
266
-    		['register', true],
267
-    	]));
268
-
269
-		$form = $this->form($request);
270
-		$form->text('foo')->required();
271
-		$form->button('register');
272
-
273
-		$this->assertContains('<p class="error_message">', $form->render());
274
-	}
275
-
276
-	/** @test */
277
-	public function it_renders_default_language()
278
-	{
279
-		$form = $this->form();
280
-		$form->text('foo')->required();
281
-		$form->button('register');
282
-
283
-		$this->assertContains('This field is required.', $form->render());
284
-	}
285
-
286
-	/** @test */
287
-	public function it_renders_default_added_language()
288
-	{
289
-		$form = $this->form();
290
-		$form->setLanguage('es');
291
-		$form->text('foo')->required();
292
-
293
-		$this->assertContains('Este campo es obligatorio.', $form->render());
294
-	}	
295
-
296
-	/** @test */
297
-	public function it_sets_own_namespace()
298
-	{	
299
-		$form = $this->form();
300
-
301
-		$this->assertSame($form->namespaces(), ['Helmut\Forms\Testing\Stubs', 'Helmut\Forms']);
302
-	}
303
-
304
-	/** @test */
305
-	public function it_can_add_a_namespace()
306
-	{
307
-		$form = $this->form();
308
-		$form->addNamespace('My\Custom\Namespace');
309
-		$form->addNamespace('My\Other\Custom\Namespace');
310
-
311
-		$this->assertSame($form->namespaces(), ['My\Other\Custom\Namespace', 'My\Custom\Namespace', 'Helmut\Forms\Testing\Stubs', 'Helmut\Forms']);
312
-	}
313
-
314
-	/** @test */
315
-	public function it_can_add_autoload_paths()
316
-	{
317
-		$form = $this->form();
318
-		$form->addPath(__DIR__.'/folder');
319
-		$form->addPath(__DIR__.'/folder/subfolder');
320
-
321
-		$paths = $form->paths();
322
-
323
-		$this->assertCount(4, $paths);
324
-		$this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
325
-		$this->assertContains('forms/tests/unit/folder/', $paths[1]);
326
-		$this->assertContains('forms/tests/unit/stubs/', $paths[2]);
327
-		$this->assertContains('forms/src/', $paths[3]);
328
-	}
329
-
330
-	/** @test */
331
-	public function it_will_not_add_autoload_paths_that_do_not_exist()
332
-	{
333
-		$form = $this->form();
334
-		$form->addPath(__DIR__.'/folder');
335
-		$form->addPath(__DIR__.'/folder/subfolder');
336
-		$form->addPath(__DIR__.'/folder/doesnotexist');
337
-
338
-		$paths = $form->paths();
339
-
340
-		$this->assertCount(4, $paths);
341
-		$this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
342
-		$this->assertContains('forms/tests/unit/folder/', $paths[1]);
343
-		$this->assertContains('forms/tests/unit/stubs/', $paths[2]);
344
-		$this->assertContains('forms/src/', $paths[3]);
345
-	}	
346
-
347
-	/** @test */
348
-	public function it_adds_autoload_paths_with_trailing_slash()
349
-	{
350
-		$form = $this->form();
351
-		$form->addPath(__DIR__.'/folder/');
352
-		$form->addPath(__DIR__.'/folder/subfolder/');
353
-
354
-		$paths = $form->paths();
355
-
356
-		$this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
357
-		$this->assertContains('forms/tests/unit/folder/', $paths[1]);
358
-		$this->assertContains('forms/tests/unit/stubs/', $paths[2]);
359
-		$this->assertContains('forms/src/', $paths[3]);
360
-	}
361
-
362
-	/** @test */
363
-	public function it_can_set_template()
364
-	{
365
-		$form = $this->form();
366
-		$form->setTemplate('testing');
367
-
368
-		$paths = $form->templatePaths();
369
-
370
-		$this->assertCount(1, $paths);
371
-		$this->assertContains('forms/tests/unit/stubs/templates/testing/', $paths[0]);
372
-	}
373
-
374
-	/** @test */
375
-	public function it_will_not_add_template_path_that_does_not_exist()
376
-	{
377
-		$form = $this->form();
378
-		$form->setTemplate('doesnotexist');
379
-
380
-		$paths = $form->templatePaths();
381
-
382
-		$this->assertCount(0, $paths);
383
-	}	
384
-
385
-	/** @test */
386
-	public function it_sets_template_autoload_path()
387
-	{
388
-		$form = $this->form();
317
+        $form = $this->form();
318
+        $form->addPath(__DIR__.'/folder');
319
+        $form->addPath(__DIR__.'/folder/subfolder');
320
+
321
+        $paths = $form->paths();
322
+
323
+        $this->assertCount(4, $paths);
324
+        $this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
325
+        $this->assertContains('forms/tests/unit/folder/', $paths[1]);
326
+        $this->assertContains('forms/tests/unit/stubs/', $paths[2]);
327
+        $this->assertContains('forms/src/', $paths[3]);
328
+    }
329
+
330
+    /** @test */
331
+    public function it_will_not_add_autoload_paths_that_do_not_exist()
332
+    {
333
+        $form = $this->form();
334
+        $form->addPath(__DIR__.'/folder');
335
+        $form->addPath(__DIR__.'/folder/subfolder');
336
+        $form->addPath(__DIR__.'/folder/doesnotexist');
337
+
338
+        $paths = $form->paths();
339
+
340
+        $this->assertCount(4, $paths);
341
+        $this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
342
+        $this->assertContains('forms/tests/unit/folder/', $paths[1]);
343
+        $this->assertContains('forms/tests/unit/stubs/', $paths[2]);
344
+        $this->assertContains('forms/src/', $paths[3]);
345
+    }	
346
+
347
+    /** @test */
348
+    public function it_adds_autoload_paths_with_trailing_slash()
349
+    {
350
+        $form = $this->form();
351
+        $form->addPath(__DIR__.'/folder/');
352
+        $form->addPath(__DIR__.'/folder/subfolder/');
353
+
354
+        $paths = $form->paths();
355
+
356
+        $this->assertContains('forms/tests/unit/folder/subfolder', $paths[0]);
357
+        $this->assertContains('forms/tests/unit/folder/', $paths[1]);
358
+        $this->assertContains('forms/tests/unit/stubs/', $paths[2]);
359
+        $this->assertContains('forms/src/', $paths[3]);
360
+    }
361
+
362
+    /** @test */
363
+    public function it_can_set_template()
364
+    {
365
+        $form = $this->form();
366
+        $form->setTemplate('testing');
367
+
368
+        $paths = $form->templatePaths();
369
+
370
+        $this->assertCount(1, $paths);
371
+        $this->assertContains('forms/tests/unit/stubs/templates/testing/', $paths[0]);
372
+    }
373
+
374
+    /** @test */
375
+    public function it_will_not_add_template_path_that_does_not_exist()
376
+    {
377
+        $form = $this->form();
378
+        $form->setTemplate('doesnotexist');
379
+
380
+        $paths = $form->templatePaths();
381
+
382
+        $this->assertCount(0, $paths);
383
+    }	
384
+
385
+    /** @test */
386
+    public function it_sets_template_autoload_path()
387
+    {
388
+        $form = $this->form();
389 389
 		
390
-		$paths = $form->templatePaths();
391
-
392
-		$this->assertCount(2, $paths);
393
-		$this->assertContains('forms/tests/unit/stubs/templates/bootstrap/', $paths[0]);
394
-		$this->assertContains('forms/src/templates/bootstrap/', $paths[1]);
395
-	}
396
-
397
-	/** @test */
398
-	public function it_uses_added_autoload_paths_to_find_templates()
399
-	{
400
-		$form = $this->form();
401
-		$form->addPath(__DIR__.'/folder');
402
-
403
-		$paths = $form->templatePaths();
404
-
405
-		$this->assertCount(3, $paths);
406
-		$this->assertContains('forms/tests/unit/folder/templates/bootstrap/', $paths[0]);
407
-		$this->assertContains('forms/tests/unit/stubs/templates/bootstrap/', $paths[1]);
408
-		$this->assertContains('forms/src/templates/bootstrap/', $paths[2]);
409
-	}
410
-
411
-	/** @test */
412
-	public function it_uses_added_autoload_paths_to_find_templates_with_a_set_template()
413
-	{
414
-		$form = $this->form();
415
-		$form->setTemplate('testing');
416
-		$form->addPath(__DIR__.'/folder');
417
-
418
-		$paths = $form->templatePaths();
419
-
420
-		$this->assertCount(2, $paths);
421
-		$this->assertContains('forms/tests/unit/folder/templates/testing/', $paths[0]);
422
-		$this->assertContains('forms/tests/unit/stubs/templates/testing/', $paths[1]);
423
-	}	
424
-
425
-	/** @test */
426
-	public function it_sets_your_namespace_as_an_autoload_path()
427
-	{
428
-    	$form = new FormWithCustomNamespace($this->request());
429
-		$form->removeAllPlugins();
430
-
431
-		$paths = $form->paths();
432
-
433
-		$this->assertCount(2, $paths);
434
-		$this->assertContains('tests/unit/stubs/Custom/', $paths[0]);
435
-		$this->assertContains('forms/src/', $paths[1]);
436
-	}
437
-
438
-	/** @test */
439
-	public function it_sets_your_namespace_and_parent_namespaces_as_an_autoload_path()
440
-	{
441
-    	$form = new FormWithCustomExtension($this->request());
442
-		$form->removeAllPlugins();
443
-
444
-		$paths = $form->paths();
445
-
446
-		$this->assertCount(3, $paths);
447
-		$this->assertContains('tests/unit/stubs/CustomExtension/', $paths[0]);
448
-		$this->assertContains('tests/unit/stubs/CustomExtension/FormExtension/', $paths[1]);
449
-		$this->assertContains('forms/src/', $paths[2]);
450
-	}
451
-
452
-	/** @test */
453
-	public function it_sets_your_namespace_template_autoload_path_with_added_template()
454
-	{
455
-    	$form = new FormWithCustomNamespace($this->request());
456
-		$form->removeAllPlugins();    	
457
-		$form->setTemplate('testing');
458
-
459
-		$paths = $form->templatePaths();
460
-
461
-		$this->assertCount(1, $paths);
462
-		$this->assertContains('tests/unit/stubs/Custom/templates/testing/', $paths[0]);
463
-	}		
464
-
465
-	/** @test */
466
-	public function it_renders_using_your_namespace_template()
467
-	{
468
-    	$form = new FormWithCustomNamespace($this->request());
469
-		$form->removeAllPlugins();
470
-
471
-		$this->assertContains('it_renders_using_your_namespace_template', $form->render());
472
-	}
390
+        $paths = $form->templatePaths();
391
+
392
+        $this->assertCount(2, $paths);
393
+        $this->assertContains('forms/tests/unit/stubs/templates/bootstrap/', $paths[0]);
394
+        $this->assertContains('forms/src/templates/bootstrap/', $paths[1]);
395
+    }
396
+
397
+    /** @test */
398
+    public function it_uses_added_autoload_paths_to_find_templates()
399
+    {
400
+        $form = $this->form();
401
+        $form->addPath(__DIR__.'/folder');
402
+
403
+        $paths = $form->templatePaths();
404
+
405
+        $this->assertCount(3, $paths);
406
+        $this->assertContains('forms/tests/unit/folder/templates/bootstrap/', $paths[0]);
407
+        $this->assertContains('forms/tests/unit/stubs/templates/bootstrap/', $paths[1]);
408
+        $this->assertContains('forms/src/templates/bootstrap/', $paths[2]);
409
+    }
410
+
411
+    /** @test */
412
+    public function it_uses_added_autoload_paths_to_find_templates_with_a_set_template()
413
+    {
414
+        $form = $this->form();
415
+        $form->setTemplate('testing');
416
+        $form->addPath(__DIR__.'/folder');
417
+
418
+        $paths = $form->templatePaths();
419
+
420
+        $this->assertCount(2, $paths);
421
+        $this->assertContains('forms/tests/unit/folder/templates/testing/', $paths[0]);
422
+        $this->assertContains('forms/tests/unit/stubs/templates/testing/', $paths[1]);
423
+    }	
424
+
425
+    /** @test */
426
+    public function it_sets_your_namespace_as_an_autoload_path()
427
+    {
428
+        $form = new FormWithCustomNamespace($this->request());
429
+        $form->removeAllPlugins();
430
+
431
+        $paths = $form->paths();
432
+
433
+        $this->assertCount(2, $paths);
434
+        $this->assertContains('tests/unit/stubs/Custom/', $paths[0]);
435
+        $this->assertContains('forms/src/', $paths[1]);
436
+    }
437
+
438
+    /** @test */
439
+    public function it_sets_your_namespace_and_parent_namespaces_as_an_autoload_path()
440
+    {
441
+        $form = new FormWithCustomExtension($this->request());
442
+        $form->removeAllPlugins();
443
+
444
+        $paths = $form->paths();
445
+
446
+        $this->assertCount(3, $paths);
447
+        $this->assertContains('tests/unit/stubs/CustomExtension/', $paths[0]);
448
+        $this->assertContains('tests/unit/stubs/CustomExtension/FormExtension/', $paths[1]);
449
+        $this->assertContains('forms/src/', $paths[2]);
450
+    }
451
+
452
+    /** @test */
453
+    public function it_sets_your_namespace_template_autoload_path_with_added_template()
454
+    {
455
+        $form = new FormWithCustomNamespace($this->request());
456
+        $form->removeAllPlugins();    	
457
+        $form->setTemplate('testing');
458
+
459
+        $paths = $form->templatePaths();
460
+
461
+        $this->assertCount(1, $paths);
462
+        $this->assertContains('tests/unit/stubs/Custom/templates/testing/', $paths[0]);
463
+    }		
464
+
465
+    /** @test */
466
+    public function it_renders_using_your_namespace_template()
467
+    {
468
+        $form = new FormWithCustomNamespace($this->request());
469
+        $form->removeAllPlugins();
470
+
471
+        $this->assertContains('it_renders_using_your_namespace_template', $form->render());
472
+    }
473 473
 
474 474
 }
475 475
\ No newline at end of file
Please login to merge, or discard this patch.
src/templates/foundation/config.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php 
2 2
 
3 3
 return [
4
-	'plugins' => [
5
-		'feedback',
6
-	],
4
+    'plugins' => [
5
+        'feedback',
6
+    ],
7 7
 ];
8 8
\ No newline at end of file
Please login to merge, or discard this patch.
src/Fields/Dropdown/Dropdown.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.
src/Fields/Text/Text.php 1 patch
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function setValuesFromDefaults($defaults)
27 27
     {
28
-        if (count($defaults)) $this->value = array_shift($defaults);
28
+        if (count($defaults)) {
29
+            $this->value = array_shift($defaults);
30
+        }
29 31
     }
30 32
 
31 33
     public function setValuesFromModel($model)
32 34
     {
33
-        if (property_exists($model, $this->name)) $this->value = $model->{$this->name};
35
+        if (property_exists($model, $this->name)) {
36
+            $this->value = $model->{$this->name};
37
+        }
34 38
     }
35 39
 
36 40
     public function setValuesFromRequest($request)
@@ -40,7 +44,9 @@  discard block
 block discarded – undo
40 44
 
41 45
     public function fillModelWithValues($model)
42 46
     {
43
-        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value;
47
+        if (property_exists($model, $this->name)) {
48
+            $model->{$this->name} = $this->value;
49
+        }
44 50
     }   
45 51
 
46 52
     public function validateRequired()
Please login to merge, or discard this patch.