Passed
Push — main ( 172775...d66992 )
by Michiel
06:24
created

ChmodTaskTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 49
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 3 1
A testChangeModeDirSet() 0 8 1
A testChangeModeFile() 0 8 1
A setUp() 0 4 1
A testChangeModeFileSet() 0 8 1
A testInvalidMode() 0 5 1
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
 * Tests the Chmod Task.
28
 *
29
 * @author  Michiel Rook <[email protected]>
30
 *
31
 * @internal
32
 */
33
class ChmodTaskTest extends BuildFileTest
34
{
35
    public function setUp(): void
36
    {
37
        $this->configureProject(
38
            PHING_TEST_BASE . '/etc/tasks/system/ChmodTaskTest.xml'
39
        );
40
    }
41
42
    public function tearDown(): void
43
    {
44
        $this->executeTarget('clean');
45
    }
46
47
    public function testChangeModeFile(): void
48
    {
49
        $this->executeTarget(__FUNCTION__);
50
51
        clearstatcache();
52
        $mode = fileperms(PHING_TEST_BASE . '/etc/tasks/system/tmp/chmodtest');
53
54
        $this->assertEquals(octdec('0700'), $mode & 0777, 'chmodtest mode should have changed to 0400');
55
    }
56
57
    public function testChangeModeFileSet(): void
58
    {
59
        $this->executeTarget(__FUNCTION__);
60
61
        clearstatcache();
62
        $mode = fileperms(PHING_TEST_BASE . '/etc/tasks/system/tmp/chmodtest');
63
64
        $this->assertEquals(octdec('0700'), $mode & 0777, 'chmodtest mode should have changed to 0400');
65
    }
66
67
    public function testChangeModeDirSet(): void
68
    {
69
        $this->executeTarget(__FUNCTION__);
70
71
        clearstatcache();
72
        $mode = fileperms(PHING_TEST_BASE . '/etc/tasks/system/tmp/A');
73
74
        $this->assertEquals(octdec('0700'), $mode & 0777, 'chmodtest mode should have changed to 0400');
75
    }
76
77
    public function testInvalidMode(): void
78
    {
79
        $this->expectException(BuildException::class);
80
        $this->expectExceptionMessage('You have specified an invalid mode.');
81
        $this->executeTarget(__FUNCTION__);
82
    }
83
}
84