Passed
Push — main ( ba819d...a8e5ae )
by Michiel
06:08
created

PhpEvalTaskTest::testOneScalarParam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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