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

ImportTaskTest::testImportedTarget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Test\Task\System;
21
22
use Phing\Io\File;
23
use Phing\Test\Support\BuildFileTest;
24
25
/**
26
 * @author Bryan Davis <[email protected]>
27
 */
28
class ImportTaskTest extends BuildFileTest
29
{
30
    public function setUp(): void
31
    {
32
        $this->configureProject(PHING_TEST_BASE . "/etc/tasks/importing.xml");
33
    }
34
35
    public function testOverloadedTarget()
36
    {
37
        $f1 = new File(PHING_TEST_BASE . "/etc/tasks/importing.xml");
38
39
        $this->executeTarget("main");
40
        $this->assertInLogs("This is " . $f1->getAbsolutePath() . " main target.");
41
    }
42
43
    public function testImportedTarget()
44
    {
45
        $f1 = new File(PHING_TEST_BASE . "/etc/tasks/imports/imported.xml");
46
        $f2 = new File(PHING_TEST_BASE . "/etc/tasks/imports");
47
48
        $this->executeTarget("imported");
49
        $this->assertInLogs("phing.file.imported=" . $f1->getAbsolutePath());
50
        $this->assertInLogs("imported.basedir=" . $f2->getAbsolutePath());
51
    }
52
53
    public function testImported2Target()
54
    {
55
        $f1 = new File(PHING_TEST_BASE . "/etc/tasks/imports/importedImport.xml");
56
57
        $this->executeTarget("imported2");
58
        $this->assertInLogs("This is " . $f1->getAbsolutePath() . " imported2 target.");
59
    }
60
61
    public function testImportedMultiTarget()
62
    {
63
        $this->configureProject(PHING_TEST_BASE . "/etc/tasks/importing-multi.xml");
64
65
        $this->assertInLogs("parsing buildfile imported-multi-1.xml");
66
        $this->assertInLogs("parsing buildfile imported-multi-2.xml");
67
    }
68
69
    public function testCascadeTarget()
70
    {
71
        $f1 = new File(PHING_TEST_BASE . "/etc/tasks/imports/imported.xml");
72
        $f2 = new File(PHING_TEST_BASE . "/etc/tasks/importing.xml");
73
74
        $this->executeTarget("cascade");
75
        $this->assertInLogs("This comes from the imported.properties file");
76
        $this->assertInLogs("This is " . $f1->getAbsolutePath() . " main target.");
77
        $this->assertInLogs("This is " . $f2->getAbsolutePath() . " cascade target.");
78
    }
79
80
    public function testFlipFlopTarget()
81
    {
82
        // calls target in main that depends on target in import that depends on
83
        // target orverridden in main
84
        $this->executeTarget("flipflop");
85
        $f1 = new File(PHING_TEST_BASE . "/etc/tasks/importing.xml");
86
        $f2 = new File(PHING_TEST_BASE . "/etc/tasks/imports/imported.xml");
87
        $this->assertInLogs("This is " . $f1->getAbsolutePath() . " flop target.");
88
        $this->assertInLogs("This is " . $f2->getAbsolutePath() . " flip target.");
89
        $this->assertInLogs("This is " . $f1->getAbsolutePath() . " flipflop target.");
90
    }
91
92
    public function testOnlyTopLevel()
93
    {
94
        $this->expectBuildExceptionContaining(
95
            __FUNCTION__,
96
            'Import can only be used as a top-level task',
97
            'import only allowed as a top-level task'
98
        );
99
    }
100
}
101