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

ChownTaskTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 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
/**
21
 * Tests the Chown Task
22
 *
23
 * @author  Michiel Rook <[email protected]>
24
 * @package phing.tasks.system
25
 */
26
class ChownTaskTest extends BuildFileTest
27
{
28
    public function setUp(): void
29
    {
30
        $this->configureProject(
31
            PHING_TEST_BASE . '/etc/tasks/system/ChownTaskTest.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...
32
        );
33
    }
34
35
    public function tearDown(): void
36
    {
37
        $this->executeTarget('clean');
38
    }
39
40
    public function testChangeGroup()
41
    {
42
        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
43
            $this->markTestSkipped("chown tests don't work on Windows");
44
        }
45
46
        $userinfo = posix_getpwuid(posix_geteuid());
47
        $username = $userinfo['name'];
48
49
        //we may change the group only if we belong to it
50
        //so find a group that we are in
51
        $group = null;
52
        foreach (['users', 'www-data', 'cdrom'] as $groupname) {
53
            $grpinfo = posix_getgrnam($groupname);
54
            if ($grpinfo['gid'] == $userinfo['gid']) {
55
                //current group id, the file has that group anyway
56
                continue;
57
            }
58
            if (!is_array($grpinfo['members'])) {
59
                continue;
60
            }
61
            if (in_array($username, $grpinfo['members'])) {
62
                $group = $grpinfo;
63
                break;
64
            }
65
        }
66
        if ($group === null) {
67
            $this->markTestSkipped('found no group we can change ownership to');
68
        }
69
70
        $this->project->setUserProperty(
71
            'targetuser',
72
            $username . '.' . $group['name']
73
        );
74
        $this->executeTarget(__FUNCTION__);
75
        $a = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestA');
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...
76
        $b = stat(PHING_TEST_BASE . '/etc/tasks/system/tmp/chowntestB');
77
78
        $this->assertNotEquals(
79
            $group['gid'],
80
            $a['gid'],
81
            'chowntestA group should not have changed'
82
        );
83
        $this->assertEquals(
84
            $group['gid'],
85
            $b['gid'],
86
            'chowntestB group should have changed'
87
        );
88
    }
89
}
90