Passed
Push — main ( 7d351e...d05000 )
by Michiel
07:03
created

circularDefinitionTargetsProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Test\Task\System;
22
23
use Phing\Exception\BuildException;
24
use Phing\Test\Support\BuildFileTest;
25
26
/**
27
 * @author Hans Lellelid (Phing)
28
 * @author Conor MacNeill (Ant)
29
 *
30
 * @internal
31
 */
32
class PropertyTaskTest extends BuildFileTest
33
{
34
    public function setUp(): void
35
    {
36
        $this->configureProject(PHING_TEST_BASE . '/etc/tasks/property.xml');
37
    }
38
39
    public function test1(): void
40
    {
41
        putenv('MESSAGE=foo bar baz');
42
        $this->executeTarget(__FUNCTION__);
43
        $this->assertPropertyEquals('testenv.MESSAGE', 'foo bar baz');
44
    }
45
46
    public function test2(): void
47
    {
48
        $this->expectLog('test2', 'testprop1=aa, testprop3=xxyy, testprop4=aazz');
49
    }
50
51
    public function testPropertyInFileShouldShadowExistingPropertyWithSameName(): void
52
    {
53
        $this->expectLog(__FUNCTION__, 'http.url is http://localhost:80');
54
        $this->assertPropertyEquals('http.port', '999');
55
    }
56
57
    public function testOverrideExistingPropertyWithNewProperty(): void
58
    {
59
        $this->executeTarget(__FUNCTION__);
60
        $this->assertPropertyEquals('http.port', '80');
61
    }
62
63
    public function testOverrideExistingPropertyWithNewPropertyFromFile(): void
64
    {
65
        $this->executeTarget(__FUNCTION__);
66
        $this->assertPropertyEquals('http.port', '80');
67
    }
68
69
    public function testPrefixSuccess(): void
70
    {
71
        $this->executeTarget('prefix.success');
72
        $this->assertEquals('80', $this->project->getProperty('server1.http.port'));
73
    }
74
75
    public function testPrefixFailure(): void
76
    {
77
        $this->expectException(BuildException::class);
78
        $this->expectExceptionMessageMatches('/Prefix is only valid/');
79
80
        $this->executeTarget('prefix.fail');
81
    }
82
83
    public function testFilterChain(): void
84
    {
85
        $this->executeTarget(__FUNCTION__);
86
        $this->assertEquals('World', $this->project->getProperty('filterchain.test'));
87
    }
88
89
    public static function circularDefinitionTargetsProvider(): array
90
    {
91
        return [
92
            ['test3'],
93
            ['testCircularDefinition1'],
94
            ['testCircularDefinition2'],
95
        ];
96
    }
97
98
    /**
99
     * @dataProvider circularDefinitionTargetsProvider
100
     *
101
     * @param mixed $target
102
     */
103
    #[\PHPUnit\Framework\Attributes\DataProvider('circularDefinitionTargetsProvider')]
104
    public function testCircularDefinitionDetection($target): void
105
    {
106
        $this->expectException(BuildException::class);
107
        $this->expectExceptionMessageMatches('/was circularly defined/');
108
109
        $this->executeTarget($target);
110
    }
111
112
    public function testToString(): void
113
    {
114
        $this->expectLog(__FUNCTION__, 'sourcefiles = filehash.bin');
115
    }
116
117
    /**
118
     * Inspired by @see http://www.phing.info/trac/ticket/1118
119
     * This test should not throw exceptions.
120
     */
121
    public function testUsingPropertyTwiceInPropertyValueShouldNotThrowException(): void
122
    {
123
        $this->expectNotToPerformAssertions();
124
        $this->executeTarget(__FUNCTION__);
125
    }
126
127
    public function testRequired(): void
128
    {
129
        $this->expectBuildException(__FUNCTION__, 'Unable to find property file.');
130
    }
131
}
132