Completed
Push — master ( 1e93da...c2b934 )
by Daniel
33:59
created

EditableFormFieldTest::testLengthRange()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 29
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package userforms
5
 */
6
7
class EditableFormFieldTest extends FunctionalTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
9
	static $fixture_file = 'userforms/tests/EditableFormFieldTest.yml';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fixture_file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
10
11
	function testFormFieldPermissions() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
		$text = $this->objFromFixture('EditableTextField', 'basic-text');
13
14
		$this->logInWithPermission('ADMIN');
15
		$this->assertTrue($text->canCreate());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
		$this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
		$this->assertTrue($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
18
		$this->assertTrue($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
20
		$text->setReadonly(true);
21
		$this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
		$this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
		$this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
25
		$text->setReadonly(false);
26
		$this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
		$this->assertTrue($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
		$this->assertTrue($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
30
		$member = Member::currentUser();
31
		$member->logout();
32
33
		$this->logInWithPermission('SITETREE_VIEW_ALL');
34
		$this->assertFalse($text->canCreate());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
36
		$text->setReadonly(false);
37
		$this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
		$this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
		$this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
		$text->setReadonly(true);
42
		$this->assertTrue($text->canView());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
43
		$this->assertFalse($text->canEdit());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
		$this->assertFalse($text->canDelete());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
	}
46
47
	function testCustomRules() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
		$this->logInWithPermission('ADMIN');
49
		$form = $this->objFromFixture('UserDefinedForm', 'custom-rules-form');
50
51
		$checkbox = $form->Fields()->find('ClassName', 'EditableCheckbox');
0 ignored issues
show
Bug introduced by
The method Fields() does not exist on DataObject. Did you maybe mean beforeUpdateCMSFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
52
		$field = $form->Fields()->find('ClassName', 'EditableTextField');
0 ignored issues
show
Bug introduced by
The method Fields() does not exist on DataObject. Did you maybe mean beforeUpdateCMSFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
53
54
		$rules = $checkbox->DisplayRules();
55
56
		// form has 2 fields - a checkbox and a text field
57
		// it has 1 rule - when ticked the checkbox hides the text field
58
		$this->assertEquals(1, $rules->Count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
		$this->assertEquals($rules, $checkbox->EffectiveDisplayRules());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
61
		$checkboxRule = $rules->First();
62
		$checkboxRule->ConditionFieldID = $field->ID;
63
64
		$this->assertEquals($checkboxRule->Display, 'Hide');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
		$this->assertEquals($checkboxRule->ConditionOption, 'HasValue');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
		$this->assertEquals($checkboxRule->FieldValue, '6');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
68
		// If field is required then all custom rules are disabled
69
		$checkbox->Required = true;
70
		$this->assertEquals(0, $checkbox->EffectiveDisplayRules()->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
	}
72
73 View Code Duplication
	function testEditableDropdownField() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

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...
74
		$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown');
75
76
		$field = $dropdown->getFormField();
77
78
79
		$this->assertThat($field, $this->isInstanceOf('DropdownField'));
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method assertThat() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
		$values = $field->getSource();
81
82
		$this->assertEquals(array('Option 1' => 'Option 1', 'Option 2' => 'Option 2'), $values);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
	}
84
85 View Code Duplication
	function testEditableRadioField() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

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...
86
		$radio = $this->objFromFixture('EditableRadioField', 'radio-field');
87
88
		$field = $radio->getFormField();
89
90
		$this->assertThat($field, $this->isInstanceOf('OptionsetField'));
0 ignored issues
show
Bug introduced by
The method isInstanceOf() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method assertThat() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
		$values = $field->getSource();
92
93
		$this->assertEquals(array('Option 5' => 'Option 5', 'Option 6' => 'Option 6'), $values);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
94
	}
95
96
	function testMultipleOptionDuplication() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
97
		$dropdown = $this->objFromFixture('EditableDropdown','basic-dropdown');
98
99
		$clone = $dropdown->duplicate();
100
101
		$this->assertEquals($clone->Options()->Count(), $dropdown->Options()->Count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
102
103
		foreach($clone->Options() as $option) {
104
			$orginal = $dropdown->Options()->find('Title', $option->Title);
105
106
			$this->assertEquals($orginal->Sort, $option->Sort);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
		}
108
	}
109
110
	public function testFileField() {
111
		$fileField = $this->objFromFixture('EditableFileField', 'file-field');
112
		$formField = $fileField->getFormField();
113
114
		$this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
115
		$this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
116
	}
117
118
	public function testFileFieldAllowedExtensionsBlacklist() {
119
		Config::inst()->update('EditableFileField', 'allowed_extensions_blacklist', array('jpg'));
120
		$fileField = $this->objFromFixture('EditableFileField', 'file-field');
121
		$formField = $fileField->getFormField();
122
123
		$this->assertNotContains('jpg', $formField->getValidator()->getAllowedExtensions());
124
	}
125
126
	/**
127
	 * Verify that unique names are automatically generated for each formfield
128
	 */
129
	public function testUniqueName() {
130
		$textfield1 = new EditableTextField();
131
		$this->assertEmpty($textfield1->Name);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
133
		// Write values
134
		$textfield1->write();
135
		$textfield2 = new EditableTextField();
136
		$textfield2->write();
137
		$checkboxField = new EditableCheckbox();
138
		$checkboxField->write();
139
140
		// Test values are in the expected format
141
		$this->assertRegExp('/^EditableTextField_.+/', $textfield1->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
142
		$this->assertRegExp('/^EditableTextField_.+/', $textfield2->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143
		$this->assertRegExp('/^EditableCheckbox_.+/', $checkboxField->Name);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
144
		$this->assertNotEquals($textfield1->Name, $textfield2->Name);
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
145
	}
146
147
    public function testLengthRange() {
148
        /** @var EditableTextField $textField */
149
        $textField = $this->objFromFixture('EditableTextField', 'basic-text');
150
151
        // Empty range
152
        /** @var TextField $formField */
153
        $textField->MinLength = 0;
0 ignored issues
show
Documentation introduced by
The property MinLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

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...
154
        $textField->MaxLength = 0;
0 ignored issues
show
Documentation introduced by
The property MaxLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

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...
155
        $attributes = $textField->getFormField()->getAttributes();
156
        $this->assertFalse(isset($attributes['maxLength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
157
        $this->assertFalse(isset($attributes['data-rule-minlength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
158
        $this->assertFalse(isset($attributes['data-rule-maxlength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
159
160
        // Test valid range
161
        $textField->MinLength = 10;
0 ignored issues
show
Documentation introduced by
The property MinLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

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...
162
        $textField->MaxLength = 20;
0 ignored issues
show
Documentation introduced by
The property MaxLength does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

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...
163
        $attributes = $textField->getFormField()->getAttributes();
164
        $this->assertEquals(20, $attributes['maxLength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
165
        $this->assertEquals(20, $attributes['size']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
        $this->assertEquals(10, $attributes['data-rule-minlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
167
        $this->assertEquals(20, $attributes['data-rule-maxlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
168
169
        // textarea
170
        $textField->Rows = 3;
0 ignored issues
show
Documentation introduced by
The property Rows does not exist on object<EditableTextField>. Since you implemented __set, maybe consider adding a @property annotation.

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...
171
        $attributes = $textField->getFormField()->getAttributes();
172
        $this->assertFalse(isset($attributes['maxLength']));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
173
        $this->assertEquals(10, $attributes['data-rule-minlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
174
        $this->assertEquals(20, $attributes['data-rule-maxlength']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<EditableFormFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
    }
176
177
178
}
179