JFormFieldTextareaTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 7
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
4
 * @license    GNU General Public License version 2 or later; see LICENSE
5
 */
6
7
namespace Joomla\Form\Tests;
8
9
use Joomla\Test\TestHelper;
10
use Joomla\Form\Field_Textarea;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17 View Code Duplication
class JFormFieldTextareaTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
18
{
19
	/**
20
	 * Sets up dependancies for the test.
21
	 *
22
	 * @return void
23
	 */
24
	protected function setUp()
25
	{
26
		// The real class cannot be autoloaded
27
		\Joomla\Form\FormHelper::loadFieldClass('textarea');
28
29
		parent::setUp();
30
	}
31
32
	/**
33
	 * Test the getInput method.
34
	 *
35
	 * @return void
36
	 */
37
	public function testGetInput()
38
	{
39
		$form = new JFormInspector('form1');
40
41
		$this->assertThat(
42
			$form->load('<form><field name="textarea" type="textarea" /></form>'),
43
			$this->isTrue(),
44
			'Line:' . __LINE__ . ' XML string should load successfully.'
45
		);
46
47
		/** @var Field_Textarea $field */
48
		$field = \Joomla\Form\FormHelper::loadFieldType('textarea');
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Form\FormHelper::loadFieldType() has been deprecated with message: 2.0 Field objects should be autoloaded

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
49
		$field->setForm($form);
50
51
		$this->assertThat(
52
			$field->setup($form->getXml()->field, 'value'),
53
			$this->isTrue(),
54
			'Line:' . __LINE__ . ' The setup method should return true.'
55
		);
56
57
		$this->assertThat(
58
			strlen($field->input),
0 ignored issues
show
Documentation introduced by
The property $input is declared protected in Joomla\Form\Field. 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...
59
			$this->greaterThan(0),
60
			'Line:' . __LINE__ . ' The getInput method should return something without error.'
61
		);
62
63
		// TODO: Should check all the attributes have come in properly.
64
	}
65
}
66