Passed
Push — main ( 2c83d5...fb3f8a )
by Siad
05:21
created

SubPhingTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 46
dl 0
loc 124
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ taskFinished() 0 2 1
A hp$0 ➔ messageLogged() 0 2 1
A hp$0 ➔ getError() 0 3 1
A hp$0 ➔ buildFinished() 0 2 1
A hp$0 ➔ __construct() 0 3 1
A hp$0 ➔ taskStarted() 0 2 1
B hp$0 ➔ baseDirs() 0 65 2
A hp$0 ➔ targetFinished() 0 2 1
A hp$0 ➔ buildStarted() 0 2 1
A hp$0 ➔ targetStarted() 0 13 4
A setUp() 0 4 1
baseDirs() 0 65 ?
A testNoDirs() 0 3 1
A testPhingFile() 0 16 1
A testGenericPhingFile() 0 12 1
A testPhingVersion() 0 7 1
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\Test\Task\System;
21
22
use AssertionError;
23
use Phing\Listener\BuildEvent;
24
use Phing\Listener\BuildListener;
25
use Phing\Test\Support\BuildFileTest;
26
27
/**
28
 * Tests the SubPhing Task
29
 *
30
 * @author  Siad Ardroumli <[email protected]>
31
 */
32
class SubPhingTest extends BuildFileTest
33
{
34
    public function setUp(): void
35
    {
36
        $this->configureProject(
37
            PHING_TEST_BASE . '/etc/tasks/system/subphing.xml'
38
        );
39
    }
40
41
    public function testNoDirs(): void
42
    {
43
        $this->expectLog(__FUNCTION__, 'No sub-builds to iterate on');
44
    }
45
46
    public function testGenericPhingFile(): void
47
    {
48
        $dir1 = $this->getProject()->resolveFile('.');
49
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
50
        $dir3 = $this->getProject()->resolveFile('subphing/subphing-test2');
51
52
        $this->baseDirs(
53
            __FUNCTION__,
54
            [
55
                $dir1->getAbsolutePath(),
56
                $dir2->getAbsolutePath(),
57
                $dir3->getAbsolutePath(),
58
            ]
59
        );
60
    }
61
62
    public function testPhingFile(): void
63
    {
64
        $dir1 = $this->getProject()->resolveFile('.');
65
        // basedir of subphing/subphing-test1/subphing.xml is ..
66
        // therefore we expect here the subphing/subphing-test1 subdirectory
67
        $dir2 = $this->getProject()->resolveFile('subphing/subphing-test1');
68
        // basedir of subphing/subphing-test2/subphing.xml is ..
69
        // therefore we expect here the subphing subdirectory
70
        $dir3 = $this->getProject()->resolveFile('subphing');
71
72
        $this->baseDirs(
73
            __FUNCTION__,
74
            [
75
                $dir1->getAbsolutePath(),
76
                $dir2->getAbsolutePath(),
77
                $dir3->getAbsolutePath(),
78
            ]
79
        );
80
    }
81
82
    public function testPhingVersion()
83
    {
84
        $this->markTestSkipped('Please review!');
85
        $this->executeTarget(__FUNCTION__);
86
        $this->assertPropertySet('version');
87
        $this->assertPropertySet('home');
88
        $this->assertPropertySet('classpath');
89
    }
90
91
    private function baseDirs(string $target, array $dirs): void
92
    {
93
        $bc = new class($dirs) implements BuildListener {
94
            private $expectedBasedirs;
95
            private $calls = 0;
96
            private $error;
97
98
            public function __construct(array $dirs)
99
            {
100
                $this->expectedBasedirs = $dirs;
101
            }
102
103
            public function buildStarted(BuildEvent $event)
104
            {
105
            }
106
107
            public function buildFinished(BuildEvent $event)
108
            {
109
            }
110
111
            public function targetFinished(BuildEvent $event)
112
            {
113
            }
114
115
            public function taskStarted(BuildEvent $event)
116
            {
117
            }
118
119
            public function taskFinished(BuildEvent $event)
120
            {
121
            }
122
123
            public function messageLogged(BuildEvent $event)
124
            {
125
            }
126
127
            public function targetStarted(BuildEvent $event)
128
            {
129
                if ($event->getTarget()->getName() === '') {
130
                    return;
131
                }
132
                if ($this->error === null) {
133
                    try {
134
                        BuildFileTest::assertEquals(
135
                            $this->expectedBasedirs[$this->calls++],
136
                            $event->getProject()->getBaseDir()->getAbsolutePath()
137
                        );
138
                    } catch (AssertionError $e) {
139
                        $this->error = $e;
140
                    }
141
                }
142
            }
143
144
            public function getError()
145
            {
146
                return $this->error;
147
            }
148
        };
149
        $this->getProject()->addBuildListener($bc);
150
        $this->executeTarget($target);
151
        $ae = $bc->getError();
152
        if ($ae !== null) {
153
            throw $ae;
154
        }
155
        $this->getProject()->removeBuildListener($bc);
156
    }
157
}
158