JFormRuleBooleanTest::testBoolean()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 75
rs 8.5454
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Rule\Boolean as RuleBoolean;
11
12
/**
13
 * Test class for JForm.
14
 *
15
 * @since  1.0
16
 */
17
class JFormRuleBooleanTest extends \PHPUnit_Framework_TestCase
18
{
19
	/**
20
	 * Test the Joomla\Form\Rule\Boolean::test method.
21
	 *
22
	 * @return void
23
	 */
24
	public function testBoolean()
25
	{
26
		$rule = new RuleBoolean;
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Rule\Boolean has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
27
		$xml = simplexml_load_string('<form><field name="foo" /></form>');
28
29
		// Test fail conditions.
30
31
		$this->assertThat(
32
			$rule->test($xml->field, 'bogus'),
33
			$this->isFalse(),
34
			'Line:' . __LINE__ . ' The rule should fail and return false.'
35
		);
36
37
		$this->assertThat(
38
			$rule->test($xml->field, '0_anything'),
39
			$this->isFalse(),
40
			'Line:' . __LINE__ . ' The rule should fail and return false.'
41
		);
42
43
		$this->assertThat(
44
			$rule->test($xml->field, 'anything_1_anything'),
45
			$this->isFalse(),
46
			'Line:' . __LINE__ . ' The rule should fail and return false.'
47
		);
48
49
		$this->assertThat(
50
			$rule->test($xml->field, 'anything_true_anything'),
51
			$this->isFalse(),
52
			'Line:' . __LINE__ . ' The rule should fail and return false.'
53
		);
54
55
		$this->assertThat(
56
			$rule->test($xml->field, 'anything_false'),
57
			$this->isFalse(),
58
			'Line:' . __LINE__ . ' The rule should fail and return false.'
59
		);
60
61
		// Test pass conditions.
62
63
		$this->assertThat(
64
			$rule->test($xml->field, 0),
65
			$this->isTrue(),
66
			'Line:' . __LINE__ . ' The rule should pass and return true.'
67
		);
68
69
		$this->assertThat(
70
			$rule->test($xml->field, '0'),
71
			$this->isTrue(),
72
			'Line:' . __LINE__ . ' The rule should pass and return true.'
73
		);
74
75
		$this->assertThat(
76
			$rule->test($xml->field, 1),
77
			$this->isTrue(),
78
			'Line:' . __LINE__ . ' The rule should pass and return true.'
79
		);
80
81
		$this->assertThat(
82
			$rule->test($xml->field, '1'),
83
			$this->isTrue(),
84
			'Line:' . __LINE__ . ' The rule should pass and return true.'
85
		);
86
87
		$this->assertThat(
88
			$rule->test($xml->field, 'true'),
89
			$this->isTrue(),
90
			'Line:' . __LINE__ . ' The rule should pass and return true.'
91
		);
92
93
		$this->assertThat(
94
			$rule->test($xml->field, 'false'),
95
			$this->isTrue(),
96
			'Line:' . __LINE__ . ' The rule should pass and return true.'
97
		);
98
	}
99
}
100