Completed
Push — master ( d87474...50d944 )
by Siad
14:47
created

PosixPermissionsSelectorTest::isSelected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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
use PHPUnit\Framework\TestCase;
21
use OsCondition as Os;
22
23
/**
24
 * Class PosixPermissionsSelectorTest
25
 */
26
class PosixPermissionsSelectorTest extends TestCase
27
{
28
    /** @var PosixPermissionsSelector $selector */
29
    private $selector;
30
31
    protected function setUp(): void
32
    {
33
        if (!Os::isFamily(Os::FAMILY_UNIX)) {
34
            $this->markTestSkipped('Not POSIX');
35
        }
36
37
        $this->selector = new PosixPermissionsSelector();
38
    }
39
40
    public function tearDown(): void
41
    {
42
        $this->selector = null;
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function argumentRequired(): void
49
    {
50
        $this->expectException(BuildException::class);
51
        $this->expectExceptionMessage('the permissions attribute is required');
52
53
        $this->selector->isSelected(new PhingFile(__DIR__), '', new PhingFile(__FILE__));
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function isSelected(): void
60
    {
61
        $this->selector->setPermissions('rw-rw-r--');
62
        $this->assertTrue(
63
            $this->selector->isSelected(
64
                new PhingFile(__DIR__),
65
                (new PhingFile(__FILE__))->getName(),
66
                new PhingFile(__FILE__)
67
            ),
68
            'File permission is wrong. Actual ' . decoct(fileperms(__FILE__) & 0777)
69
        );
70
    }
71
72
    /**
73
     * @test
74
     * @dataProvider illegalArgumentProvider
75
     * @dataProvider legalArgumentProvider
76
     * @param string $permission
77
     * @param bool $throws
78
     */
79
    public function argument(string $permission, $throws = false): void
80
    {
81
        if ($throws) {
82
            $this->expectException(BuildException::class);
83
        } else {
84
            $this->expectNotToPerformAssertions();
85
        }
86
87
        $this->selector->setPermissions($permission);
88
    }
89
90
    public function legalArgumentProvider(): array
91
    {
92
        return [
93
            'legal octal string' => ['750'],
94
            'legal posix string' => ['rwxr-x---'],
95
        ];
96
    }
97
98
    public function illegalArgumentProvider(): array
99
    {
100
        return [
101
            ['855', true],
102
            ['4555', true],
103
            ['-rwxr-xr-x', true],
104
            ['xrwr-xr-x', true],
105
        ];
106
    }
107
}
108