|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jasny; |
|
4
|
|
|
|
|
5
|
|
|
use PHPStan\Testing\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Test function handling functions |
|
9
|
|
|
*/ |
|
10
|
|
|
class FuncFunctionsTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function strReplaceNamedArgProvider() |
|
13
|
|
|
{ |
|
14
|
|
|
return [ |
|
15
|
|
|
['bablamas blamo coblam', ['subject' => 'bananas nano conan', 'search' => 'nan', 'replace' => 'blam']], |
|
16
|
|
|
['bablamas blamo coblam', ['search' => 'nan', 'subject' => 'bananas nano conan', 'replace' => 'blam']], |
|
17
|
|
|
['bablamas blamo coblam', ['replace' => 'blam', 'search' => 'nan', 'subject' => 'bananas nano conan']] |
|
18
|
|
|
]; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @dataProvider strReplaceNamedArgProvider |
|
23
|
|
|
* @covers Jasny\call_user_func_assoc |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $expect |
|
26
|
|
|
* @param array $args |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testCallUserFuncAssocStrReplace($expect, array $args) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertEquals($expect, call_user_func_assoc('str_replace', $args)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function strTrNamedArgProvider() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
['yzywyzyny', ['str' => 'abawabana', 'from' => 'ab', 'to' => 'yz']], |
|
37
|
|
|
['yzywyzyny', ['str' => 'abawabana', 'from' => ['a' => 'y', 'b' => 'z']]], |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @dataProvider strTrNamedArgProvider |
|
43
|
|
|
* @covers Jasny\call_user_func_assoc |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $expect |
|
46
|
|
|
* @param array $args |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testCallUserFuncAssocStrTr($expect, array $args) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->assertEquals($expect, call_user_func_assoc('strtr', $args)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @covers Jasny\call_user_func_assoc |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testCallUserFuncAssocDateTime() |
|
57
|
|
|
{ |
|
58
|
|
|
$date = new \DateTime("2017-01-02T00:00:00+0000"); |
|
59
|
|
|
$this->assertEquals('2017-01-02', call_user_func_assoc([$date, 'format'], ['format' => 'Y-m-d'])); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @covers Jasny\call_user_func_assoc |
|
65
|
|
|
* |
|
66
|
|
|
* @expectedException \BadFunctionCallException |
|
67
|
|
|
* @expectedExceptionMessage Missing argument 'search' for str_replace() |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testCallUserFuncAssocStrReplaceInvalid() |
|
70
|
|
|
{ |
|
71
|
|
|
call_user_func_assoc('str_replace', ['subject' => 'foo', 'replace' => 'o']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @covers Jasny\call_user_func_assoc |
|
76
|
|
|
* |
|
77
|
|
|
* @expectedException \BadFunctionCallException |
|
78
|
|
|
* @expectedExceptionMessage Missing argument 'format' for DateTime::format() |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testCallUserFuncAssocDateTimeInvalid() |
|
81
|
|
|
{ |
|
82
|
|
|
$date = new \DateTime("2017-01-02T00:00:00+0000"); |
|
83
|
|
|
call_user_func_assoc([$date, 'format'], []); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|