1
|
|
|
<?php |
2
|
|
|
class HelperTest extends \PHPUnit\Framework\TestCase |
3
|
|
|
{ |
4
|
|
|
public function testDataGetKeyIsNull() |
5
|
|
|
{ |
6
|
|
|
$dataArr = array('test' => 42); |
7
|
|
|
|
8
|
|
|
$this->assertEquals($dataArr, dataGet($dataArr, null)); |
9
|
|
|
$this->assertEquals(42, dataGet($dataArr, 'test')); |
10
|
|
|
$this->assertEquals(43, dataGet($dataArr, 'test-unknown', 43)); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function testP() |
14
|
|
|
{ |
15
|
|
|
$this->expectOutputString("<pre>\n1\n</pre><pre>\nArray\n(\n [a] => 1\n)\n\n</pre>"); |
16
|
|
|
_p(1); |
17
|
|
|
|
18
|
|
|
_p(['a' => 1]); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testHead() |
22
|
|
|
{ |
23
|
|
|
$arr = ['a' => 1, 'b' => 2, 'c' => 3]; |
24
|
|
|
$this->assertSame(1, head($arr)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testLast() |
28
|
|
|
{ |
29
|
|
|
$arr = ['a' => 1, 'b' => 2, 'c' => 3]; |
30
|
|
|
$this->assertSame(3, last($arr)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testFlatten() |
34
|
|
|
{ |
35
|
|
|
$arr = ['a' => 1, 'b' => 2, 'c' => ['s1' => 3, 's2' => 4]]; |
36
|
|
|
$this->assertSame([1, 2, 3, 4], flatten($arr)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testValue() |
40
|
|
|
{ |
41
|
|
|
$value = 1; |
42
|
|
|
$this->assertSame(1, value($value)); |
43
|
|
|
|
44
|
|
|
$value = function() { |
45
|
|
|
return 2; |
46
|
|
|
}; |
47
|
|
|
$this->assertSame(2, value($value)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function testCamelCase() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$str = 'this_is_a_test'; |
53
|
|
|
$this->assertSame('ThisIsATest', camelCase($str)); |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.