Passed
Push — master ( 972120...1c77fc )
by Michiel
08:19
created

SubPhingTest.php$0 ➔ taskStarted()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
namespace Phing\Tasks\System;
21
22
use AssertionError;
23
use Phing\Listener\BuildEvent;
24
use Phing\Listener\BuildListener;
25
use Phing\Support\BuildFileTest;
26
27
/**
28
 * Tests the SubPhing Task
29
 *
30
 * @author  Siad Ardroumli <[email protected]>
31
 * @package phing.tasks.system
32
 */
33
class SubPhingTest extends BuildFileTest
34
{
35
    public function setUp(): void
36
    {
37
        $this->configureProject(
38
            PHING_TEST_BASE . '/etc/tasks/system/subphing.xml'
39
        );
40
    }
41
42
    public function testNoDirs(): void
43
    {
44
        $this->expectLog(__FUNCTION__, 'No sub-builds to iterate on');
45
    }
46
47
    public function testGenericPhingFile(): void
48
    {
49
        $dir1 = $this->getProject()->resolveFile('.');
50
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
51
        $dir3 = $this->getProject()->resolveFile('subphing/subphing-test2');
52
53
        $this->baseDirs(
54
            __FUNCTION__,
55
            [
56
                $dir1->getAbsolutePath(),
57
                $dir2->getAbsolutePath(),
58
                $dir3->getAbsolutePath()
59
            ]
60
        );
61
    }
62
63
    public function testPhingFile(): void
64
    {
65
        $dir1 = $this->getProject()->resolveFile('.');
66
        // basedir of subphing/subphing-test1/subphing.xml is ..
67
        // therefore we expect here the subphing/subphing-test1 subdirectory
68
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
69
        // basedir of subphing/subphing-test2/subphing.xml is ..
70
        // therefore we expect here the subphing subdirectory
71
        $dir3 = $this->getProject()->resolveFile('subphing');
72
73
        $this->baseDirs(
74
            __FUNCTION__,
75
            [
76
                $dir1->getAbsolutePath(),
77
                $dir2->getAbsolutePath(),
78
                $dir3->getAbsolutePath()
79
            ]
80
        );
81
    }
82
83
    public function testPhingVersion()
84
    {
85
        $this->markTestSkipped('Please review!');
86
        $this->executeTarget(__FUNCTION__);
87
        $this->assertPropertySet('version');
88
        $this->assertPropertySet('home');
89
        $this->assertPropertySet('classpath');
90
    }
91
92
    /**
93
     * @param string $target
94
     * @param array $dirs
95
     */
96
    private function baseDirs(string $target, array $dirs): void
97
    {
98
        $bc = new class ($dirs) implements BuildListener {
99
            private $expectedBasedirs;
100
            private $calls = 0;
101
            private $error;
102
103
            public function __construct(array $dirs)
104
            {
105
                $this->expectedBasedirs = $dirs;
106
            }
107
108
            public function buildStarted(BuildEvent $event)
109
            {
110
            }
111
112
            public function buildFinished(BuildEvent $event)
113
            {
114
            }
115
116
            public function targetFinished(BuildEvent $event)
117
            {
118
            }
119
120
            public function taskStarted(BuildEvent $event)
121
            {
122
            }
123
124
            public function taskFinished(BuildEvent $event)
125
            {
126
            }
127
128
            public function messageLogged(BuildEvent $event)
129
            {
130
            }
131
132
            public function targetStarted(BuildEvent $event)
133
            {
134
                if ($event->getTarget()->getName() === '') {
135
                    return;
136
                }
137
                if ($this->error === null) {
138
                    try {
139
                        BuildFileTest::assertEquals(
140
                            $this->expectedBasedirs[$this->calls++],
141
                            $event->getProject()->getBaseDir()->getAbsolutePath()
142
                        );
143
                    } catch (AssertionError $e) {
144
                        $this->error = $e;
145
                    }
146
                }
147
            }
148
149
            public function getError()
150
            {
151
                return $this->error;
152
            }
153
        };
154
        $this->getProject()->addBuildListener($bc);
155
        $this->executeTarget($target);
156
        $ae = $bc->getError();
157
        if ($ae !== null) {
158
            throw $ae;
159
        }
160
        $this->getProject()->removeBuildListener($bc);
161
    }
162
}
163