Passed
Push — master ( 601cfd...7bcbf1 )
by Michiel
22:46
created

SymlinkTaskTest::testOverwriteDanglingSymlink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
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\Task\System;
21
22
use Phing\Support\BuildFileTest;
23
24
/**
25
 * Tests the Symlink Task
26
 *
27
 * @author  Michiel Rook <[email protected]>
28
 * @package phing.tasks.system
29
 * @requires OS Linux
30
 */
31
class SymlinkTaskTest extends BuildFileTest
32
{
33
    public function setUp(): void
34
    {
35
        $this->configureProject(
36
            PHING_TEST_BASE
37
            . "/etc/tasks/ext/SymlinkTaskTest.xml"
38
        );
39
        $this->executeTarget("setup");
40
    }
41
42
    public function tearDown(): void
43
    {
44
        $this->executeTarget("clean");
45
    }
46
47
    public function testSymlinkExists()
48
    {
49
        $this->executeTarget(__FUNCTION__);
50
        $this->assertEquals(
51
            PHING_TEST_BASE . "/etc/tasks/ext/tmp/fake1",
52
            readlink(PHING_TEST_BASE . "/etc/tasks/ext/tmp/l")
53
        );
54
        $this->assertInLogs("Link exists: ");
55
    }
56
57
    public function testOverwritingSymlink()
58
    {
59
        $this->executeTarget(__FUNCTION__);
60
        $this->assertEquals(
61
            PHING_TEST_BASE . "/etc/tasks/ext/tmp/fake2",
62
            readlink(PHING_TEST_BASE . "/etc/tasks/ext/tmp/l")
63
        );
64
        $this->assertInLogs("Link removed: ");
65
    }
66
67
    public function testOverwritingDirectory()
68
    {
69
        $this->executeTarget(__FUNCTION__);
70
        $this->assertEquals(
71
            PHING_TEST_BASE . "/etc/tasks/ext/tmp/fake1",
72
            readlink(PHING_TEST_BASE . "/etc/tasks/ext/tmp/l")
73
        );
74
        $this->assertInLogs("Directory removed: ");
75
    }
76
77
    public function testNotOverwritingSymlink()
78
    {
79
        $this->executeTarget(__FUNCTION__);
80
        $this->assertEquals(
81
            PHING_TEST_BASE . "/etc/tasks/ext/tmp/fake1",
82
            readlink(PHING_TEST_BASE . "/etc/tasks/ext/tmp/l")
83
        );
84
        $this->assertInLogs("Not overwriting existing link");
85
    }
86
87
    public function testOverwriteDanglingSymlink()
88
    {
89
        $this->executeTarget(__FUNCTION__);
90
        $this->assertInLogs("Link removed: ");
91
        $this->assertEquals(
92
            PHING_TEST_BASE . "/etc/tasks/ext/tmp/fake2",
93
            readlink(PHING_TEST_BASE . "/etc/tasks/ext/tmp/l")
94
        );
95
    }
96
}
97