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