Completed
Push — master ( 03e47f...db33ac )
by WEBEWEB
06:42 queued 01:35
created

StringUtilityTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 2
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseArray() 0 14 1
A testParseBoolean() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2017 NdC/WBW
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Tests\Utility;
13
14
use PHPUnit_Framework_TestCase;
15
use WBW\Library\Core\Utility\StringUtility;
16
17
/**
18
 * String utility test.
19
 *
20
 * @author NdC/WBW <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Tests\Utility
22
 * @final
23
 */
24
final class StringUtilityTest extends PHPUnit_Framework_TestCase {
25
26
	/**
27
	 * Tests the parseArray() method.
28
	 *
29
	 * @return void
30
	 */
31
	public function testParseArray() {
32
33
		$arg1	 = ["exception" => null, "id" => "id", "class" => "class"];
34
		$res1	 = "id=\"id\" class=\"class\"";
35
		$this->assertEquals($res1, StringUtility::parseArray($arg1));
36
37
		$arg2	 = ["exception" => null, "id" => "    id   ", "class" => " class "];
38
		$res2	 = "id=\"id\" class=\"class\"";
39
		$this->assertEquals($res2, StringUtility::parseArray($arg2));
40
41
		$arg3	 = ["exception" => null, "id" => "id", "class" => ["class1", "class2", "class3   class4"]];
42
		$res3	 = "id=\"id\" class=\"class1 class2 class3 class4\"";
43
		$this->assertEquals($res3, StringUtility::parseArray($arg3));
44
	}
45
46
	/**
47
	 * Tests the parseBoolean() method.
48
	 *
49
	 * @return void
50
	 */
51
	public function testParseBoolean() {
52
53
		$this->assertEquals("false", StringUtility::parseBoolean(null));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a boolean.

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...
54
		$this->assertEquals("false", StringUtility::parseBoolean(false));
55
		$this->assertEquals("true", StringUtility::parseBoolean(true));
56
	}
57
58
}
59