1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Phing\Test\Task\System; |
6
|
|
|
|
7
|
|
|
use Phing\Test\Support\BuildFileTest; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Mahmoud Al-Husseiny <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class PhpEvalTaskTest extends BuildFileTest |
13
|
|
|
{ |
14
|
|
|
public static function recursiveProcess(array $arr): string |
15
|
|
|
{ |
16
|
|
|
// ensure n-d array (n > 1) |
17
|
|
|
$isMultiDimArray = false; |
18
|
|
|
foreach ($arr as $value) { |
19
|
|
|
if (is_array($value) && !empty($value)) { |
20
|
|
|
$isMultiDimArray = true; |
21
|
|
|
break; |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
static::assertTrue( |
25
|
|
|
$isMultiDimArray, |
26
|
|
|
'You must provide a multidimensional array for this test' |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$arraySum = ''; |
30
|
|
|
array_walk_recursive($arr, function ($item) use (&$arraySum) { |
31
|
|
|
$arraySum .= $item; |
32
|
|
|
}); |
33
|
|
|
|
34
|
|
|
return $arraySum; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function setUp(): void |
38
|
|
|
{ |
39
|
|
|
$this->configureProject(PHING_TEST_BASE . '/etc/tasks/system/PhpEvalTest.xml'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testZeroParams() |
43
|
|
|
{ |
44
|
|
|
$expected = get_include_path(); |
45
|
|
|
|
46
|
|
|
$this->executeTarget(__FUNCTION__); |
47
|
|
|
$this->assertPropertyEquals('result', $expected); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testOneScalarParam() |
51
|
|
|
{ |
52
|
|
|
$expected = trim(' test '); |
53
|
|
|
|
54
|
|
|
$this->executeTarget(__FUNCTION__); |
55
|
|
|
$this->assertPropertyEquals('result', $expected); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testMultiScalarParams() |
59
|
|
|
{ |
60
|
|
|
$expected = trim('##**test**##', '#'); |
61
|
|
|
|
62
|
|
|
$this->executeTarget(__FUNCTION__); |
63
|
|
|
$this->assertPropertyEquals('result', $expected); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testArrayParam() |
67
|
|
|
{ |
68
|
|
|
$expected = implode(['Phing', ' ', '3']); |
69
|
|
|
|
70
|
|
|
$this->executeTarget(__FUNCTION__); |
71
|
|
|
$this->assertPropertyEquals('result', $expected); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testMixedParams() |
75
|
|
|
{ |
76
|
|
|
$expected = implode(' ', ['Phing', '3']); |
77
|
|
|
|
78
|
|
|
$this->executeTarget(__FUNCTION__); |
79
|
|
|
$this->assertPropertyEquals('result', $expected); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testStaticMethodWithMultiDimArrayParam() |
83
|
|
|
{ |
84
|
|
|
$expected = static::recursiveProcess(['a', ['b', 'c'], 'd']); |
85
|
|
|
|
86
|
|
|
$this->executeTarget(__FUNCTION__); |
87
|
|
|
$this->assertPropertyEquals('result', $expected); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|