FormTest   D
last analyzed

Complexity

Total Complexity 87

Size/Duplication

Total Lines 980
Duplicated Lines 19.69 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 193
loc 980
rs 4.4444
c 0
b 0
f 0
wmc 87
lcom 1
cbo 5

83 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testConstructorThrowsExceptionWhenFirstArgumentMissing() 0 4 1
A testConstructorArgsAreSet() 5 12 3
A testSetMethodThrowsInvalidArgumentException() 0 4 1
A testSetMethod() 0 10 1
A testGetMethod() 0 9 1
A testSetAction() 5 19 3
A testGetAction() 0 7 1
A testMethodsetTargetThrowsException() 0 4 1
A testMethodsetTarget() 0 6 1
A testGetAutocomplete() 0 5 1
A testSetAutocomplete() 0 8 1
A testGetNoValidation() 0 5 1
A testSetNoValidation() 0 12 1
A testGetAttribute() 0 7 1
A testSetAttribute() 0 7 1
A testSetAttributes() 0 12 1
A testCopyObjectProperties() 0 20 1
A testSetID() 0 5 1
A testSetName() 0 5 1
A testGetAcceptCharset() 0 10 1
A testSetClass() 0 7 1
A testSetDescription() 0 7 1
A testSetHeading() 0 7 1
A testGetEncoding() 0 10 1
A testSetLegend() 0 10 1
A testSetLegend_allowsMethodChaining() 0 6 1
A testFormHasErrors() 0 4 1
A testregisterDefaultFormelementDecorators() 0 15 1
A testRenderAllFormelements() 0 10 1
A testRenderAllFormelementsThrowsException() 0 4 1
A testuseDefaultFormDecoratorsMethodTrue() 10 10 1
A testregisterDefaultFormDecorators() 8 8 1
A testremoveDecorator() 0 7 1
A testgetDecorator() 0 7 1
A testgetDecoratorNotFoundException() 0 5 1
A testRender() 10 10 1
A testRenderWithDecorator() 0 21 1
A testRenderViaToString() 11 11 1
A testAddElement() 0 11 1
A testAddElementAddingFileElementSetsEncoding() 0 5 1
A testAddElementWithMultipleElements() 0 12 1
A testAddElementSwitchEncodingWhenUsingFormelementFile() 0 6 1
A testDelElementByName() 0 10 1
A testGetElementByPosition() 0 11 1
A testGetElementByName() 0 7 1
A testGetElement_ByNameOrByPositionOrLastElement() 0 16 1
A testFormelementFactory() 0 6 1
A testMethodprocessForm() 0 11 1
A testMethodprocessForm_withIncommingData() 0 15 1
A testSetFormelementDecoratorFormelementPositionNull() 13 13 1
A testAddFormelementDecorator() 14 14 1
A testAddFormelementDecorator_ThrowsExceptionWhenNoFormelementsFound() 0 4 1
A testRemoveFormelementDecorator() 15 15 1
A testSetDecorator() 10 10 1
A testAddDecorator() 10 10 1
A testGetDecorators() 8 8 1
A testDecoratorFactory() 0 6 1
A testsetDecoratorAttributesArray() 0 7 1
A testAddValidator() 0 6 1
A testValidateFormFalse() 0 16 1
A testValidateForm_true() 13 13 1
A testsetRequired() 8 8 1
A testIsRequired() 7 7 1
A testhasErrors() 0 10 1
A testaddErrorMessage() 0 7 1
A testaddErrorMessages() 0 6 1
A testresetErrorMessages() 0 8 1
A testgetErrorMessages() 0 6 1
A testMagicSet() 0 7 1
A testMagicGet() 0 8 1
A testSetAttributesContainFormKey() 0 18 1
A testSetFormelements() 0 9 1
A testuseDefaultFormDecoratorsDisableViaConstructor() 0 7 1
A testAddElement_toSpecificPositions() 0 11 1
A testAddElementWithSettingAttributes() 0 18 1
A testAddElementToCertainPosition() 23 23 1
A testregenerateFormelementIdentifiers() 23 23 1
A testsetValuesDataArrayPassedToMethod() 0 17 1
A testgetValues() 0 17 1
A testapplyDecoratorAttributes() 0 20 1
A testaddErrorMessagesOverwriteMessages() 0 9 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like FormTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FormTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace KochTest\Form;
4
5
use Koch\Form\Elements;
6
use Koch\Form\Form;
7
8
/**
9
 * @todo method chaining tests on all setter methods
10
 */
11
class FormTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var Form
15
     */
16
    protected $form;
17
18
    /**
19
     * Sets up the fixture, for example, opens a network connection.
20
     * This method is called before a test is executed.
21
     */
22
    public function setUp()
23
    {
24
        $this->form = new Form('TestForm');
25
    }
26
27
    /**
28
     * Tears down the fixture, for example, closes a network connection.
29
     * This method is called after a test is executed.
30
     */
31
    public function tearDown()
32
    {
33
        unset($this->form);
34
    }
35
36
    /**
37
     * @covers Koch\Form\Form::__construct
38
     * @expectedException InvalidArgumentException
39
     * @expectedExceptionMessage
40
     */
41
    public function testConstructorThrowsExceptionWhenFirstArgumentMissing()
42
    {
43
        $this->form = new Form();
44
    }
45
46
    /**
47
     * @covers Koch\Form\Form::__construct
48
     */
49
    public function testConstructorArgsAreSet()
50
    {
51
        $this->form = new Form('Form', 'GET', 'someActionName');
52
53
        $this->assertEquals('GET', $this->form->getMethod());
54 View Code Duplication
        if (defined('REWRITE_ENGINE_ON') and REWRITE_ENGINE_ON) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
55
            $expectedURL = WWW_ROOT . 'someActionName';
56
        } else {
57
            $expectedURL = WWW_ROOT . 'index.php?mod=someActionName';
58
        }
59
        $this->assertEquals($expectedURL, $this->form->getAction());
60
    }
61
62
    /**
63
     * @expectedException InvalidArgumentException
64
     * @expectedExceptionMessage The method parameter is "abc", but has to be GET or POST.
65
     */
66
    public function testSetMethodThrowsInvalidArgumentException()
67
    {
68
        $this->form->setMethod('abc');
69
    }
70
71
    public function testSetMethod()
72
    {
73
        $this->form->setMethod('GET');
74
75
        // via getter
76
        $this->assertNotEquals('get', $this->form->getMethod());
77
        $this->assertEquals('GET', $this->form->getMethod());
78
        // via property
79
        $this->assertEquals('GET', $this->form->method);
0 ignored issues
show
Documentation introduced by
The property $method is declared protected in Koch\Form\Form. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
80
    }
81
82
    public function testGetMethod()
83
    {
84
        // defaults to POST
85
        $this->assertEquals('POST', $this->form->getMethod());
86
87
        $this->form->setMethod('GET');
88
        // via getter
89
        $this->assertEquals('GET', $this->form->getMethod());
90
    }
91
92
    public function testSetAction()
93
    {
94
        // set internal url - rebuilds the external url via router
95
        $this->form->setAction('/news/show');
96 View Code Duplication
        if (defined('REWRITE_ENGINE_ON') and REWRITE_ENGINE_ON) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
97
            $expectedURL = WWW_ROOT . 'news/show';
98
        } else {
99
            $expectedURL = WWW_ROOT . 'index.php?mod=news&amp;ctrl=show';
100
        }
101
        $this->assertEquals($expectedURL, $this->form->getAction());
102
103
        // set external url
104
        $this->form->setAction(WWW_ROOT . 'index.php?mod=news&action=show');
105
        $this->assertEquals(WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction());
106
107
        // set external url withput www_root (http root)
108
        $this->form->setAction('index.php?mod=news&action=show');
109
        $this->assertEquals(WWW_ROOT . 'index.php?mod=news&action=show', $this->form->getAction());
110
    }
111
112
    public function testGetAction()
113
    {
114
        // via getter - qualified url
115
        $url = WWW_ROOT . 'index.php?mod=news&action=show';
116
        $this->form->setAction($url);
117
        $this->assertEquals($url, $this->form->getAction());
118
    }
119
120
    /**
121
     * @expectedException InvalidArgumentException
122
     * @expectedExceptionMessage The target parameter is "abc", but has to be one of _blank, _self, _parent, _top.
123
     */
124
    public function testMethodsetTargetThrowsException()
125
    {
126
        $this->form->setTarget('abc');
127
    }
128
129
    /**
130
     * @covers Koch\Form\Form::getTarget
131
     * @covers Koch\Form\Form::setTarget
132
     */
133
    public function testMethodsetTarget()
134
    {
135
        $this->form->setTarget('_self');
136
137
        $this->assertEquals('_self', $this->form->getTarget());
138
    }
139
140
    public function testGetAutocomplete()
141
    {
142
        $this->form->setAutoComplete(false);
143
        $this->assertEquals('off', $this->form->isAutoComplete());
144
    }
145
146
    public function testSetAutocomplete()
147
    {
148
        $this->form->setAutoComplete(false);
149
        $this->assertEquals('off', $this->form->isAutoComplete());
150
151
        $this->form->setAutoComplete(true);
152
        $this->assertEquals('on', $this->form->isAutoComplete());
153
    }
154
155
    public function testGetNoValidation()
156
    {
157
        $this->form->setNoValidation(true);
158
        $this->assertEquals('novalidate', $this->form->isNoValidation());
159
    }
160
161
    public function testSetNoValidation()
162
    {
163
        $this->form->setNoValidation(false);
164
165
        // via getter - returns empty string
166
        $this->assertEquals('', $this->form->isNoValidation());
167
168
        $this->form->setNoValidation(true);
169
170
        // via getter - returns string
171
        $this->assertEquals('novalidate', $this->form->isNoValidation());
172
    }
173
174
    public function testGetAttribute()
175
    {
176
        $this->form->setAttribute('myAttribute', true);
0 ignored issues
show
Documentation introduced by
'myAttribute' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
178
        // via getter - returns string
179
        $this->assertEquals(true, $this->form->getAttribute('myAttribute'));
180
    }
181
182
    public function testSetAttribute()
183
    {
184
        $this->form->setAttribute('myAttribute', true);
0 ignored issues
show
Documentation introduced by
'myAttribute' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
185
186
        // via getter - returns string
187
        $this->assertEquals(true, $this->form->getAttribute('myAttribute'));
188
    }
189
190
    public function testSetAttributes()
191
    {
192
        $array = ['attr1' => 'val1', 'attr2' => true];
193
194
        $this->form->setAttributes($array);
195
196
        // via getter - returns string
197
        $this->assertEquals('val1', $this->form->getAttribute('attr1'));
198
        $this->assertEquals(true, $this->form->getAttribute('attr2'));
199
200
        unset($array);
201
    }
202
203
    public function testSetAttributesContainFormKey()
204
    {
205
        $this->markTestSkipped('Depends on Form\Generator\PHPArray');
206
207
        $attributes = [
208
            'attr1' => 'val1',
209
            'attr2' => true,
210
            'form'  => [
211
                'name'   => 'formname',
212
                'action' => 'someAction',
213
                'method' => 'POST',
214
                'key-a'  => 'value-a',
215
                'key-b'  => 'value-b',
216
            ],
217
        ];
218
219
        $this->form->setAttributes($attributes);
220
    }
221
222
    public function testCopyObjectProperties()
223
    {
224
        // prefilled object
225
        $from_object_a                   = new \stdClass();
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
226
        $from_object_a->attribute_string = 'value_of_attr_a';
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
227
        $from_object_a->attribute_int    = 9;
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
228
        $from_object_a->attribute_bool   = true;
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
229
        $from_object_a->attribute_array  = ['key' => 'value'];
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
230
231
        // empty target object
232
        $to_object_b = new \stdClass();
0 ignored issues
show
Coding Style introduced by
$to_object_b does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
233
234
        $this->form->copyObjectProperties($from_object_a, $to_object_b);
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
235
236
        $this->assertEquals($from_object_a, $to_object_b);
0 ignored issues
show
Coding Style introduced by
$from_object_a does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
237
        $this->assertEquals($to_object_b->attribute_string, 'value_of_attr_a');
0 ignored issues
show
Coding Style introduced by
$to_object_b does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
238
        $this->assertEquals($to_object_b->attribute_int, 9);
0 ignored issues
show
Coding Style introduced by
$to_object_b does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
239
        $this->assertEquals($to_object_b->attribute_bool, true);
0 ignored issues
show
Coding Style introduced by
$to_object_b does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
240
        $this->assertEquals($to_object_b->attribute_array['key'], 'value');
0 ignored issues
show
Coding Style introduced by
$to_object_b does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
241
    }
242
243
    /**
244
     * @covers Koch\Form\Form::setID()
245
     * @covers Koch\Form\Form::getID()
246
     */
247
    public function testSetID()
248
    {
249
        $this->form->setId('identifier1');
250
        $this->assertEquals('identifier1', $this->form->getId());
251
    }
252
253
    /**
254
     * @covers Koch\Form\Form::setName()
255
     * @covers Koch\Form\Form::getName()
256
     */
257
    public function testSetName()
258
    {
259
        $this->form->setName('name1');
260
        $this->assertEquals('name1', $this->form->getName());
261
    }
262
263
    /**
264
     * @covers Koch\Form\Form::setAcceptCharset()
265
     * @covers Koch\Form\Form::getAcceptCharset()
266
     */
267
    public function testGetAcceptCharset()
268
    {
269
        // via getter - returns default value utf-8 as string
270
        $this->assertEquals('utf-8', $this->form->getAcceptCharset());
271
272
        $this->form->setAcceptCharset('iso-8859-1');
273
274
        // via getter - returns string
275
        $this->assertEquals('iso-8859-1', $this->form->getAcceptCharset());
276
    }
277
278
    /**
279
     * @covers Koch\Form\Form::setClass()
280
     * @covers Koch\Form\Form::getClass()
281
     */
282
    public function testSetClass()
283
    {
284
        $this->form->setClass('cssclassname1');
285
286
        // via getter - returns string
287
        $this->assertEquals('cssclassname1', $this->form->getClass());
288
    }
289
290
    /**
291
     * @covers Koch\Form\Form::setDescription()
292
     * @covers Koch\Form\Form::getDescription()
293
     */
294
    public function testSetDescription()
295
    {
296
        $this->form->setDescription('description1');
297
298
        // via getter - returns string
299
        $this->assertEquals('description1', $this->form->getDescription());
300
    }
301
302
    /**
303
     * @covers Koch\Form\Form::setHeading()
304
     * @covers Koch\Form\Form::getHeading()
305
     */
306
    public function testSetHeading()
307
    {
308
        $this->form->setHeading('heading2');
309
310
        // via getter - returns string
311
        $this->assertEquals('heading2', $this->form->getHeading());
312
    }
313
314
    /**
315
     * @covers Koch\Form\Form::setEncoding()
316
     * @covers Koch\Form\Form::getEncoding()
317
     */
318
    public function testGetEncoding()
319
    {
320
        // via getter - returns default value as string
321
        $this->assertEquals('multipart/form-data', $this->form->getEncoding());
322
323
        $this->form->setEncoding('text/plain');
324
325
        // via getter - returns string
326
        $this->assertEquals('text/plain', $this->form->getEncoding());
327
    }
328
329
    /**
330
     * @covers Koch\Form\Form::setLegend()
331
     * @covers Koch\Form\Form::getLegend()
332
     */
333
    public function testSetLegend()
334
    {
335
        $this->form->setLegend('legend-set');
336
337
        // via getter - returns string
338
        $this->assertEquals('legend-set', $this->form->getLegend());
339
340
        // allows method chaining
341
        $this->assertEquals($this->form, $this->form->setLegend('returns form object'));
342
    }
343
344
    public function testSetLegend_allowsMethodChaining()
0 ignored issues
show
Coding Style introduced by
function testSetLegend_allowsMethodChaining() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
345
    {
346
        $return_value = $this->form->setLegend('returns form object');
0 ignored issues
show
Coding Style introduced by
$return_value does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
347
348
        $this->assertSame($this->form, $return_value);
0 ignored issues
show
Coding Style introduced by
$return_value does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
349
    }
350
351
    /**
352
     * @covers Koch\Form\Form::setFormelements()
353
     * @covers Koch\Form\Form::getFormelements()
354
     */
355
    public function testSetFormelements()
356
    {
357
        // via getter - returns inital empty array
358
        $this->assertEquals([], $this->form->getFormelements());
359
360
        $formelements = ['formelements'];
361
        $this->form->setFormelements($formelements);
362
        $this->assertEquals($formelements, $this->form->getFormelements());
363
    }
364
365
    public function testFormHasErrors()
366
    {
367
        $this->assertFalse($this->form->FormHasErrors());
368
    }
369
370
    public function testregisterDefaultFormelementDecorators()
371
    {
372
        $this->form->addElement('Textarea');
373
        $formelements         = $this->form->getFormelements();
374
        $textarea_formelement = $formelements['0'];
0 ignored issues
show
Coding Style introduced by
$textarea_formelement does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
375
376
        $this->form->registerDefaultFormelementDecorators($textarea_formelement);
0 ignored issues
show
Coding Style introduced by
$textarea_formelement does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
377
378
        $formelement_decorators = $textarea_formelement->getDecorators();
0 ignored issues
show
Coding Style introduced by
$formelement_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
379
380
        $this->assertFalse(empty($formelement_decorators));
0 ignored issues
show
Coding Style introduced by
$formelement_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
381
        $this->assertTrue(is_object($formelement_decorators['label']));
0 ignored issues
show
Coding Style introduced by
$formelement_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
382
        $this->assertTrue(is_object($formelement_decorators['description']));
0 ignored issues
show
Coding Style introduced by
$formelement_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
383
        $this->assertTrue(is_object($formelement_decorators['div']));
0 ignored issues
show
Coding Style introduced by
$formelement_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
384
    }
385
386
    public function testRenderAllFormelements()
387
    {
388
        $this->form->addElement('Textarea');
389
390
        $formelements_html_expected = CR . '<div class="formline"><textarea id="textarea-formelement-0"></textarea></div>' . CR;
0 ignored issues
show
Coding Style introduced by
$formelements_html_expected does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
391
392
        $formelements_html = $this->form->renderAllFormelements();
0 ignored issues
show
Coding Style introduced by
$formelements_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
393
        $this->assertFalse(empty($formelements_html));
0 ignored issues
show
Coding Style introduced by
$formelements_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
394
        $this->assertEquals($formelements_html, $formelements_html_expected);
0 ignored issues
show
Coding Style introduced by
$formelements_html does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
395
    }
396
397
    /**
398
     * @expectedException Koch\Exception\Exception
399
     * @expectedExceptionMessage Error rendering formelements. No formelements on form object. Consider adding some formelements using addElement().
400
     */
401
    public function testRenderAllFormelementsThrowsException()
402
    {
403
        $this->form->renderAllFormelements();
404
    }
405
406
    public function testuseDefaultFormDecoratorsDisableViaConstructor()
407
    {
408
        $form       = new Form(['useDefaultFormDecorators' => true]);
409
        $decorators = $form->getDecorators();
410
        $this->assertEquals([], $decorators);
411
        unset($form);
412
    }
413
414 View Code Duplication
    public function testuseDefaultFormDecoratorsMethodTrue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
415
    {
416
        $this->form->useDefaultFormDecorators(true);
417
418
        $this->form->registerDefaultFormDecorators();
419
        $default_form_decorators = $this->form->getDecorators();
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
420
        $this->assertFalse(empty($default_form_decorators));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
421
        $this->assertTrue(is_object($default_form_decorators['form']));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
422
        $this->assertTrue(is_a($default_form_decorators['form'], 'Koch\Form\AbstractFormDecorator'));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
423
    }
424
425 View Code Duplication
    public function testregisterDefaultFormDecorators()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
426
    {
427
        $this->form->registerDefaultFormDecorators();
428
        $default_form_decorators = $this->form->getDecorators();
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
429
        $this->assertFalse(empty($default_form_decorators));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
430
        $this->assertTrue(is_object($default_form_decorators['form']));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
431
        $this->assertTrue(is_a($default_form_decorators['form'], 'Koch\Form\AbstractFormDecorator'));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
432
    }
433
434
    public function testremoveDecorator()
435
    {
436
        $this->form->registerDefaultFormDecorators();
437
        $this->form->removeDecorator('form');
438
        $default_form_decorators = $this->form->getDecorators();
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
439
        $this->assertFalse(array_key_exists('form', $default_form_decorators));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
440
    }
441
442
    public function testgetDecorator()
443
    {
444
        $this->form->registerDefaultFormDecorators();
445
        $default_form_decorators = $this->form->getDecorators();
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
446
        $this->assertTrue(array_key_exists('form', $default_form_decorators));
0 ignored issues
show
Coding Style introduced by
$default_form_decorators does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
447
        $this->assertInstanceOf('Koch\Form\Decorators\Form\Form', $this->form->getDecorator('form'));
448
    }
449
450
    /*
451
     * expectedException        InvalidArgumentException
452
     * expectedExceptionMessage The Form does not have a Decorator called "not-existing-formdecorator".
453
     */
454
455
    public function testgetDecoratorNotFoundException()
456
    {
457
        $this->setExpectedException('InvalidArgumentException');
458
        $this->form->getDecorator('not-existing-formdecorator');
459
    }
460
461 View Code Duplication
    public function testRender()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
462
    {
463
        $this->form->addElement('Textarea');
464
465
        $html = $this->form->render();
466
        $this->assertFalse(empty($html));
467
        $this->assertContains('<form', $html);
468
        $this->assertContains('<textarea id="textarea-formelement-0">', $html);
469
        $this->assertContains('</form>', $html);
470
    }
471
472
    public function testRenderWithDecorator()
473
    {
474
        $this->form->addElement('Textarea');
475
        $this->form->addErrorMessage('Doh! This is an error message. Doh!');
476
        $this->form->addDecorator('Errors');
0 ignored issues
show
Documentation introduced by
'Errors' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
477
478
        $html = $this->form->render();
479
480
        $this->assertFalse(empty($html));
481
482
        // content from decorator
483
        $this->assertContains('<ul id="form-errors">', $html);
484
        $this->assertContains('<li>Doh! This is an error message. Doh!</li>', $html);
485
        $this->assertContains('</ul>', $html);
486
487
        // normal form tag
488
        $this->assertContains('<!-- Start of Form "TestForm" -->', $html);
489
        $this->assertContains('<form', $html);
490
        $this->assertContains('<textarea id="textarea-formelement-0">', $html);
491
        $this->assertContains('</form>', $html);
492
    }
493
494 View Code Duplication
    public function testRenderViaToString()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
495
    {
496
        $this->form->addElement('Textarea');
497
498
        $html = $this->form->__toString();
499
500
        $this->assertFalse(empty($html));
501
        $this->assertContains('<form', $html);
502
        $this->assertContains('<textarea id="textarea-formelement-0">', $html);
503
        $this->assertContains('</form>', $html);
504
    }
505
506
    public function testAddElement()
507
    {
508
        $this->form->addElement('Text');
509
        // $this->form->getElementByPosition('0');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
510
        $formelements_array = $this->form->getFormelements();
0 ignored issues
show
Coding Style introduced by
$formelements_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
511
512
        $formelement = new \Koch\Form\Elements\Text();
513
        $formelement->setID('text-formelement-0');
514
515
        $this->assertEquals($formelement, $formelements_array[0]);
0 ignored issues
show
Coding Style introduced by
$formelements_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
516
    }
517
518
    public function testAddElementAddingFileElementSetsEncoding()
519
    {
520
        $this->form->addElement('file');
521
        $this->assertEquals('multipart/form-data', $this->form->getEncoding());
522
    }
523
524
    public function testAddElement_toSpecificPositions()
0 ignored issues
show
Coding Style introduced by
function testAddElement_toSpecificPositions() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
525
    {
526
        $this->form->addElement('textarea', [], 'Position1');
527
        $this->form->addElement('checkbox', [], 'Position2');
528
        $this->form->addElement('submitbutton', [], 'Position3');
529
530
        $formelements = $this->form->getFormelements();
531
        $this->assertArrayHasKey('Position1', $formelements);
532
        $this->assertArrayHasKey('Position2', $formelements);
533
        $this->assertArrayHasKey('Position3', $formelements);
534
    }
535
536
    public function testAddElementWithMultipleElements()
537
    {
538
        $formelements   = [];
539
        $formelements[] = $this->form->addElement('ButtonBar');
540
        $formelements[] = $this->form->addElement('Textarea');
541
        $formelements[] = $this->form->addElement('Checkbox');
542
543
        $formelements_from_testobject = $this->form->getFormelements();
0 ignored issues
show
Coding Style introduced by
$formelements_from_testobject does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
544
545
        $this->assertNotEmpty($formelements_from_testobject);
0 ignored issues
show
Coding Style introduced by
$formelements_from_testobject does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
546
        $this->assertSame($formelements, $this->form->getFormelements());
547
    }
548
549
    public function testAddElementWithSettingAttributes()
550
    {
551
        // test element
552
        $attributes = [
553
            'class'     => 'myFormelementClass',
554
            'maxlength' => '20',
555
            'label'     => 'myFormelementLabel',
556
            'id'        => 'text-formelement-0',
557
        ];
558
559
        $this->form->addElement('Text', $attributes);
560
        $formelement = $this->form->getElementByPosition('0');
561
562
        $this->assertEquals($attributes['class'], $formelement->class);
563
        $this->assertEquals($attributes['maxlength'], $formelement->maxlength);
564
        $this->assertEquals($attributes['label'], $formelement->label);
565
        $this->assertEquals($attributes['id'], $formelement->id);
566
    }
567
568 View Code Duplication
    public function testAddElementToCertainPosition()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569
    {
570
        // PREPARE:
571
        // this will take position 0
572
        $this->form->addElement('File');
573
        // this will take position 1
574
        $this->form->addElement('Captcha');
575
576
        // TEST:
577
        // this will take position 0 + reorders the array
578
        $this->form->addElement('Text', null, 0);
579
580
        $array   = [];
581
        $array[] = new Elements\Text();    // 0 - Text
582
        $array[] = new Elements\File();    // 1 - File
583
        $array[] = new Elements\Captcha(); // 2 - Captcha
584
        // manually reapply formelement identifiers
585
        $array['0']->setID('text-formelement-0');
586
        $array['1']->setID('file-formelement-1');
587
        $array['2']->setID('captcha-formelement-2');
588
589
        $this->assertEquals($array, $this->form->getFormelements());
590
    }
591
592
    public function testAddElementSwitchEncodingWhenUsingFormelementFile()
593
    {
594
        $this->form->addElement('File');
595
596
        $this->assertContains('enctype="multipart/form-data"', $this->form->render());
597
    }
598
599 View Code Duplication
    public function testregenerateFormelementIdentifiers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
600
    {
601
        // PREPARE:
602
        // this will take position 0
603
        $this->form->addElement('File');
604
        // this will take position 1
605
        $this->form->addElement('Captcha');
606
607
        // TEST:
608
        // this will take position 0 and reorder the array
609
        $this->form->addElement('Text', null, 0);
610
611
        $array   = [];
612
        $array[] = new \Koch\Form\Elements\Text();    // 0 - Text
613
        $array[] = new \Koch\Form\Elements\File();    // 1 - File
614
        $array[] = new \Koch\Form\Elements\Captcha(); // 2 - Captcha
615
        // manually reapply formelement identifiers
616
        $array['0']->setID('text-formelement-0');
617
        $array['1']->setID('file-formelement-1');
618
        $array['2']->setID('captcha-formelement-2');
619
620
        $this->assertEquals($array, $this->form->getFormelements());
621
    }
622
623
    public function testDelElementByName()
624
    {
625
        $this->form->addElement('Textarea')->setName('myTextareaElement');
626
        $this->form->delElementByName('myTextareaElement');
627
628
        $this->assertNull($this->form->getElementByName('myTextareaElement'));
629
630
        // delete of non existing element returns false
631
        $this->assertFalse($this->form->delElementByName('a-not-existing-formelement'));
632
    }
633
634
    public function testGetElementByPosition()
635
    {
636
        $this->form->addElement('Text');
637
638
        $formelements_array = $this->form->getFormelements();
0 ignored issues
show
Coding Style introduced by
$formelements_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
639
640
        $this->assertSame($formelements_array['0'], $this->form->getElementByPosition(0));
0 ignored issues
show
Coding Style introduced by
$formelements_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
641
642
        // not existing position returns null
643
        $this->assertNull($this->form->getElementByPosition(1));
644
    }
645
646
    public function testGetElementByName()
647
    {
648
        $this->form->addElement('Button')->setName('myButton1');
649
650
        $formelement_object = $this->form->getElementByName('myButton1');
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
651
        $this->assertSame('myButton1', $formelement_object->getName());
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
652
    }
653
654
    public function testGetElement_ByNameOrByPositionOrLastElement()
0 ignored issues
show
Coding Style introduced by
function testGetElement_...PositionOrLastElement() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
655
    {
656
        $this->form->addElement('Button')->setName('myButton1');
657
658
        // ByName
659
        $formelement_object = $this->form->getElement('myButton1');
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
660
        $this->assertSame('myButton1', $formelement_object->getName());
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
661
662
        // ByPosition
663
        $formelement_object = $this->form->getElement('0');
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
664
        $this->assertSame('myButton1', $formelement_object->getName());
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
665
666
        // Default Value null as param
667
        $formelement_object = $this->form->getElement();
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
668
        $this->assertSame('myButton1', $formelement_object->getName());
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
669
    }
670
671
    public function testFormelementFactory()
672
    {
673
        $formelement_object = $this->form->formelementFactory('Url');
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
674
675
        $this->assertInstanceof('\Koch\Form\Elements\Url', $formelement_object);
0 ignored issues
show
Coding Style introduced by
$formelement_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
676
    }
677
678
    public function testMethodprocessForm()
679
    {
680
        $this->form->addElement('Textarea')->setRules('maxvalue=120')->setValue(123);
681
682
        $this->form->processForm();
683
684
        $html = $this->form->render();
685
686
        $this->assertContains('error', $html);
687
        $this->assertContains('<form', $html);
688
    }
689
690
    public function testMethodprocessForm_withIncommingData()
0 ignored issues
show
Coding Style introduced by
function testMethodprocessForm_withIncommingData() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
691
    {
692
        $this->form->addElement('Textarea')->setValue(123)->setRules('string');
693
694
        // two options were selected (array is incomming via post)
695
        $data = ['textarea-formelement-0' => 'Lore ipsum...'];
696
        $this->form->setValues($data);
697
698
        $html = $this->form->render();
699
700
        $this->assertContains('<form', $html);
701
        $this->assertContains('</form>', $html);
702
        $this->assertContains('<textarea', $html);
703
        $this->assertContains('Lore ipsum...', $html);
704
    }
705
706
    public function testsetValuesDataArrayPassedToMethod()
707
    {
708
        // create multiselect "Snacks" with three options
709
        $this->form->addElement('MultiSelect')->setName('Snacks')->setOptions(
710
            ['cola' => 'Cola', 'popcorn' => 'Popcorn', 'peanuts' => 'Peanuts']
711
        );
712
713
        // two options were selected (array is incomming via post)
714
        $data = ['snacks' => ['cola', 'popcorn']];
715
716
        $this->form->setValues($data);
717
718
        $snacks_array = $this->form->getElementByName('Snacks')->getValue();
0 ignored issues
show
Coding Style introduced by
$snacks_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
719
        $this->assertSame(count($snacks_array), 2);
0 ignored issues
show
Coding Style introduced by
$snacks_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
720
        $this->assertSame($snacks_array[0], 'cola');
0 ignored issues
show
Coding Style introduced by
$snacks_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
721
        $this->assertSame($snacks_array[1], 'popcorn');
0 ignored issues
show
Coding Style introduced by
$snacks_array does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
722
    }
723
724
    public function testgetValues()
725
    {
726
        $this->form->addElement('Textarea', ['value' => 'Some Text Inside The First Textarea']);
727
        $this->form->addElement('Textarea', ['value' => 'More Text Inside The Second Textarea']);
728
729
        $values = $this->form->getValues();
730
731
        $this->assertTrue(is_array($values));
732
        $this->assertSame(count($values), 2);
733
734
        $expected_values = [
0 ignored issues
show
Coding Style introduced by
$expected_values does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
735
            'textarea-formelement-0' => 'Some Text Inside The First Textarea',
736
            'textarea-formelement-1' => 'More Text Inside The Second Textarea',
737
        ];
738
739
        $this->assertSame($values, $expected_values);
0 ignored issues
show
Coding Style introduced by
$expected_values does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
740
    }
741
742 View Code Duplication
    public function testSetFormelementDecoratorFormelementPositionNull()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
743
    {
744
        $this->form->addElement('Textarea');
745
        $this->form->setFormelementDecorator('label', null);
746
747
        $formelements     = $this->form->getFormelements();
748
        $textarea_element = $formelements[0];
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
749
        $decorators       = $textarea_element->formelementdecorators;
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
750
751
        $this->assertTrue(is_array($decorators));
752
        $this->assertEquals(1, count($decorators));
753
        $this->assertTrue(isset($decorators['label']));
754
    }
755
756 View Code Duplication
    public function testAddFormelementDecorator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
757
    {
758
        $this->form->addElement('Textarea');
759
        $this->form->addElement('MultiSelect');
760
        $this->form->addFormelementDecorator('label', 1);
761
762
        $formelements     = $this->form->getFormelements();
763
        $textarea_element = $formelements[1];
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
764
        $decorators       = $textarea_element->formelementdecorators;
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
765
766
        $this->assertTrue(is_array($decorators));
767
        $this->assertEquals(1, count($decorators));
768
        $this->assertTrue(isset($decorators['label']));
769
    }
770
771
    /**
772
     * @expectedException RuntimeException
773
     * @expectedExceptionMessage No Formelements found. Add the formelement(s) first, then decorate!
774
     */
775
    public function testAddFormelementDecorator_ThrowsExceptionWhenNoFormelementsFound()
0 ignored issues
show
Coding Style introduced by
function testAddFormelem...enNoFormelementsFound() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
776
    {
777
        $this->form->addFormelementDecorator('label', 1);
778
    }
779
780 View Code Duplication
    public function testRemoveFormelementDecorator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
781
    {
782
        $this->form->addElement('Textarea');
783
        $this->form->addFormelementDecorator('label', 0);
784
785
        $this->form->removeFormelementDecorator('label');
786
787
        $formelements     = $this->form->getFormelements();
788
        $textarea_element = $formelements[0];
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
789
        $decorators       = $textarea_element->formelementdecorators;
0 ignored issues
show
Coding Style introduced by
$textarea_element does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
790
791
        $this->assertTrue(is_array($decorators));
792
        $this->assertEquals(0, count($decorators));
793
        $this->assertFalse(isset($decorators['label']));
794
    }
795
796 View Code Duplication
    public function testSetDecorator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
797
    {
798
        $this->form->setDecorator('label');
799
800
        $decorators = $this->form->getDecorators();
801
802
        $this->assertTrue(is_array($decorators));
803
        $this->assertEquals(1, count($decorators));
804
        $this->assertTrue(isset($decorators['label']));
805
    }
806
807 View Code Duplication
    public function testAddDecorator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
808
    {
809
        $this->form->addDecorator('label');
0 ignored issues
show
Documentation introduced by
'label' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
810
811
        $decorators = $this->form->getDecorators();
812
813
        $this->assertTrue(is_array($decorators));
814
        $this->assertEquals(1, count($decorators));
815
        $this->assertTrue(isset($decorators['label']));
816
    }
817
818 View Code Duplication
    public function testGetDecorators()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
819
    {
820
        $this->form->setDecorator('label');
821
        $decorators = $this->form->getDecorators();
822
823
        $this->assertTrue(is_array($decorators));
824
        $this->assertEquals(1, count($decorators));
825
    }
826
827
    public function testDecoratorFactory()
828
    {
829
        $form_decorator_object = $this->form->DecoratorFactory('label');
0 ignored issues
show
Coding Style introduced by
$form_decorator_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
830
831
        $this->assertInstanceOf('Koch\Form\Decorators\Form\Label', $form_decorator_object);
0 ignored issues
show
Coding Style introduced by
$form_decorator_object does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
832
    }
833
834
    /**
835
     * @covers Koch\Form\Form::setDecoratorAttributesArray()
836
     * @covers Koch\Form\Form::getDecoratorAttributesArray()
837
     */
838
    public function testsetDecoratorAttributesArray()
839
    {
840
        $attributes = ['attribute1' => 'value1'];
841
        $this->form->setDecoratorAttributesArray($attributes);
842
843
        $this->assertSame($attributes, $this->form->getDecoratorAttributesArray());
844
    }
845
846
    public function testapplyDecoratorAttributes()
847
    {
848
        // decorator type will be form
849
        // this is just another way of setting attributes to the form itself
850
        $attributes = ['form' => ['form' => // this is Koch\Form\Decorator\Form
851
                ['heading'        => 'This is the Heading of the form.',
852
                    'description' => 'This is a form description text.', ],
853
        ]];
854
855
        $this->form->setDecoratorAttributesArray($attributes);
856
857
        $this->form->registerDefaultFormDecorators();
858
859
        $this->form->applyDecoratorAttributes();
860
861
        $form_decorator_form = $this->form->getDecorator('form');
0 ignored issues
show
Coding Style introduced by
$form_decorator_form does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
862
863
        $this->assertSame('This is the Heading of the form.', $form_decorator_form->heading);
0 ignored issues
show
Coding Style introduced by
$form_decorator_form does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
864
        $this->assertSame('This is a form description text.', $form_decorator_form->description);
0 ignored issues
show
Coding Style introduced by
$form_decorator_form does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
865
    }
866
867
    public function testAddValidator()
868
    {
869
        $this->form->addElement('Textarea')->addValidator('required');
870
871
        $this->assertInstanceOf('Koch\Form\Validators\Required', $this->form->getElement()->validators[0]);
872
    }
873
874
    public function testValidateFormFalse()
875
    {
876
        $this->form->addElement('Textarea')
877
            ->setName('Textarea-testValidateForm-false')
878
            ->setRequired()
879
            ->setRules('required, string, maxlength=20');
880
        // ->setValue() is missing intentionally
881
        // no value set, but required
882
        $this->assertFalse($this->form->validateForm());
883
884
        // set a value, exceeding maxlength
885
        $element = $this->form->getElementByName('Textarea-testValidateForm-false');
886
        $element->setValue('0123456789-0123456789'); // 21 chars
887
        // max length exceeded
888
        $this->assertFalse($this->form->validateForm());
889
    }
890
891 View Code Duplication
    public function testValidateForm_true()
0 ignored issues
show
Coding Style introduced by
function testValidateForm_true() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
892
    {
893
        $this->form->addElement('Textarea')
894
            ->setName('Textarea-testValidateForm-true')
895
            ->setRequired()
896
            ->setRules('required, string, maxlength=20');
897
898
        // set value, length ok
899
        $element = $this->form->getElementByName('Textarea-testValidateForm-true');
900
        $element->setValue('01234567890123456789'); // 20 chars
901
902
        $this->assertTrue($this->form->validateForm());
903
    }
904
905 View Code Duplication
    public function testsetRequired()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
906
    {
907
        $this->form->addElement('Textarea')->setName('Textarea-A')->setRequired();
908
909
        $formelement = $this->form->getElementByName('Textarea-A');
910
        $this->assertTrue($formelement->required);
911
        $this->assertTrue($formelement->isRequired());
912
    }
913
914 View Code Duplication
    public function testIsRequired()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
915
    {
916
        $this->form->addElement('Textarea')->setName('Textarea-A')->setRequired();
917
        $formelement = $this->form->getElementByName('Textarea-A');
918
        $this->assertTrue($formelement->required);
919
        $this->assertTrue($formelement->isRequired());
920
    }
921
922
    public function testhasErrors()
923
    {
924
        $this->form->hasErrors(true);
925
        $this->assertTrue($this->form->error);
0 ignored issues
show
Documentation introduced by
The property $error is declared protected in Koch\Form\Form. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
926
        $this->assertTrue($this->form->hasErrors());
927
928
        $this->form->hasErrors(false);
929
        $this->assertFalse($this->form->error);
0 ignored issues
show
Documentation introduced by
The property $error is declared protected in Koch\Form\Form. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
930
        $this->assertFalse($this->form->hasErrors());
931
    }
932
933
    public function testaddErrorMessage()
934
    {
935
        $message = 'message text';
936
        $this->form->addErrorMessage($message);
937
        $errormessages = $this->form->getErrorMessages();
938
        $this->assertSame($message, $errormessages['0']);
939
    }
940
941
    public function testaddErrorMessages()
942
    {
943
        $set1 = ['aaa', 'bbb', 'ccc'];
944
        $this->form->addErrorMessages($set1);
945
        $this->assertSame($set1, $this->form->getErrorMessages());
946
    }
947
948
    public function testaddErrorMessagesOverwriteMessages()
949
    {
950
        $set1 = ['aaa', 'bbb', 'ccc'];
951
        $set2 = ['ddd', 'eee'];
952
        $this->form->addErrorMessages($set1);
953
        $this->assertSame($set1, $this->form->getErrorMessages());
954
        $this->form->addErrorMessages($set2);
955
        $this->assertSame($set2, $this->form->getErrorMessages());
956
    }
957
958
    public function testresetErrorMessages()
959
    {
960
        $set1 = ['aaa', 'bbb', 'ccc'];
961
        $this->form->addErrorMessages($set1);
962
        $this->form->resetErrorMessages();
963
        $messages = $this->form->getErrorMessages();
964
        $this->assertTrue(empty($messages));
965
    }
966
967
    public function testgetErrorMessages()
968
    {
969
        $set1 = ['aaa', 'bbb', 'ccc'];
970
        $this->form->addErrorMessages($set1);
971
        $this->assertSame($set1, $this->form->getErrorMessages());
972
    }
973
974
    public function testMagicSet()
975
    {
976
        // this will call __set
977
        $this->form->method = 'methodname';
0 ignored issues
show
Documentation introduced by
The property $method is declared protected in Koch\Form\Form. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
978
979
        $this->assertEquals('methodname', $this->form->getMethod());
980
    }
981
982
    public function testMagicGet()
983
    {
984
        // this will call __set
985
        $this->form->method = 'methodname';
0 ignored issues
show
Documentation introduced by
The property $method is declared protected in Koch\Form\Form. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
986
987
        // this will call __get
988
        $this->assertEquals('methodname', $this->form->method);
0 ignored issues
show
Documentation introduced by
The property $method is declared protected in Koch\Form\Form. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
989
    }
990
}
991