Test Failed
Push — master ( 440ce5...0cdbc1 )
by Siad
07:01
created

MapperTest::testEmptyElementIfIsReference()   B

Complexity

Conditions 5
Paths 135

Size

Total Lines 35
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 28
nc 135
nop 0
dl 0
loc 35
rs 8.9275
c 0
b 0
f 0
1
<?php
2
3
/*
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information please see
19
 * <http://phing.info>.
20
 */
21
22
/**
23
 * Unit test for mappers.
24
 *
25
 * @author Hans Lellelid <[email protected]>
26
 * @author Stefan Bodewig <[email protected]> (Ant)
27
 * @package phing.types
28
 */
29
class MapperTest extends \PHPUnit\Framework\TestCase
30
{
31
    private $project;
32
33
    public function setUp(): void
34
    {
35
        $this->project = new Project();
36
        $this->project->setBasedir(__DIR__);
37
    }
38
39
    public function testEmptyElementIfIsReference()
40
    {
41
        $m = new Mapper($this->project);
42
        $m->setFrom("*.java");
43
        try {
44
            $m->setRefid(new Reference($this->project, "dummyref"));
45
            $this->fail("Can add reference to Mapper with from attribute set");
46
        } catch (BuildException $be) {
47
            $this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage());
48
        }
49
50
        $m = new Mapper($this->project);
51
        $m->setRefid(new Reference($this->project, "dummyref"));
52
        try {
53
            $m->setFrom("*.java");
54
            $this->fail("Can set from in Mapper that is a reference.");
55
        } catch (BuildException $be) {
56
            $this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage());
57
        }
58
59
        $m = new Mapper($this->project);
60
        $m->setRefid(new Reference($this->project, "dummyref"));
61
        try {
62
            $m->setTo("*.java");
63
            $this->fail("Can set to in Mapper that is a reference.");
64
        } catch (BuildException $be) {
65
            $this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage());
66
        }
67
        try {
68
            $m = new Mapper($this->project);
69
            $m->setRefid(new Reference($this->project, "dummyref"));
70
            $m->setType("glob");
71
            $this->fail("Can set type in Mapper that is a reference.");
72
        } catch (BuildException $be) {
73
            $this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage());
74
        }
75
    }
76
77
    public function testCircularReferenceCheck()
78
    {
79
        $m = new Mapper($this->project);
80
        $this->project->addReference("dummy", $m);
81
        $m->setRefid(new Reference($this->project, "dummy"));
82
        try {
83
            $m->getImplementation();
84
            $this->fail("Can make Mapper a Reference to itself.");
85
        } catch (BuildException $be) {
86
            $this->assertEquals("This data type contains a circular reference.", $be->getMessage());
87
        }
88
89
        // dummy1 --> dummy2 --> dummy3 --> dummy1
90
        $m1 = new Mapper($this->project);
91
        $this->project->addReference("dummy1", $m1);
92
        $m1->setRefid(new Reference($this->project, "dummy2"));
93
        $m2 = new Mapper($this->project);
94
        $this->project->addReference("dummy2", $m2);
95
        $m2->setRefid(new Reference($this->project, "dummy3"));
96
        $m3 = new Mapper($this->project);
97
        $this->project->addReference("dummy3", $m3);
98
        $m3->setRefid(new Reference($this->project, "dummy1"));
99
        try {
100
            $m1->getImplementation();
101
            $this->fail("Can make circular reference.");
102
        } catch (BuildException $be) {
103
            $this->assertEquals("This data type contains a circular reference.", $be->getMessage());
104
        }
105
106
        // dummy1 --> dummy2 --> dummy3
107
        // (which holds a glob mapper from "*.java" to "*.class"
108
        $m1 = new Mapper($this->project);
109
        $this->project->addReference("dummy1", $m1);
110
        $m1->setRefid(new Reference($this->project, "dummy2"));
111
        $m2 = new Mapper($this->project);
112
        $this->project->addReference("dummy2", $m2);
113
        $m2->setRefid(new Reference($this->project, "dummy3"));
114
        $m3 = new Mapper($this->project);
115
        $this->project->addReference("dummy3", $m3);
116
117
        $m3->setType("glob");
118
        $m3->setFrom("*.java");
119
        $m3->setTo("*.class");
120
121
        $fmm = $m1->getImplementation();
122
        $this->assertTrue($fmm instanceof GlobMapper, "Should be instance of GlobMapper");
123
        $result = $fmm->main("a.java");
124
        $this->assertEquals(1, count($result));
125
        $this->assertEquals("a.class", $result[0]);
126
    }
127
128
    public function testCopyTaskWithTwoFilesets()
129
    {
130
        $t = new TaskdefForCopyTest("test1");
131
        try {
132
            $t->setUp();
133
            $t->test1();
134
            $t->tearDown();
135
        } catch (Exception $e) {
136
            $t->tearDown();
137
            throw $e;
138
        }
139
    }
140
}
141
142
/**
143
 * @package phing.mappers
144
 */
145
class TaskdefForCopyTest extends BuildFileTest
146
{
147
    public function setUp(): void
148
    {
149
        $this->configureProject(PHING_TEST_BASE . "/etc/types/mapper.xml");
0 ignored issues
show
Bug introduced by
The constant PHING_TEST_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
150
    }
151
152
    public function tearDown(): void
153
    {
154
        $this->executeTarget("cleanup");
155
    }
156
157
    public function test1()
158
    {
159
        $this->executeTarget("test1");
160
    }
161
162
    public function test2()
163
    {
164
        $this->executeTarget("test2");
165
    }
166
167
    public function test3()
168
    {
169
        $this->executeTarget("test3");
170
        $this->assertInLogs('php1');
171
        $this->assertInLogs('php2');
172
    }
173
174
    public function test4()
175
    {
176
        $this->executeTarget("test4");
177
        $this->assertNotInLogs('.php1');
178
        $this->assertInLogs('.php2');
179
    }
180
181
    public function testCutDirsMapper()
182
    {
183
        $this->executeTarget("testCutDirsMapper");
184
        $outputDir = $this->getProject()->getProperty('output');
185
        $this->assertFileExists($outputDir . '/D');
186
        $this->assertFileExists($outputDir . '/c/E');
187
    }
188
}
189