GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 4.2-to-master ( ed215f )
by E
06:47
created

FileSystemTest::testGetAbsolutePath()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 24
rs 8.9713
c 2
b 1
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Utils\Tests\FileSystem;
4
5
use ApiGen\Utils\FileSystem;
6
use PHPUnit\Framework\TestCase;
7
8
class FileSystemTest extends TestCase
9
{
10
    /**
11
     * @var FileSystem
12
     */
13
    private $fileSystem;
14
15
    protected function setUp(): void
16
    {
17
        $this->fileSystem = new FileSystem;
18
    }
19
20
    public function testNormalizePath(): void
21
    {
22
        $backslashPath = 'C:' . DIRECTORY_SEPARATOR . 'Program Files' . DIRECTORY_SEPARATOR . 'ApiGen';
23
        $this->assertSame($backslashPath, $this->fileSystem->normalizePath($backslashPath));
24
    }
25
26 View Code Duplication
    public function testForceDir(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $filePath = TEMP_DIR . '/some/dir/file.txt';
29
        $dirPath = dirname($filePath);
30
        $this->assertFalse(file_exists($dirPath));
31
32
        $this->fileSystem->forceDir($filePath);
33
        $this->assertTrue(file_exists($dirPath));
34
    }
35
36 View Code Duplication
    public function testDeleteDir(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $dir = TEMP_DIR . '/new-dir';
39
        mkdir($dir);
40
        $this->assertTrue(file_exists($dir));
41
42
        $this->fileSystem->deleteDir($dir);
43
        $this->assertFalse(file_exists($dir));
44
    }
45
46
    public function testPurgeDir(): void
47
    {
48
        $dir = TEMP_DIR . '/dir-with-content';
49
        mkdir($dir);
50
        mkdir($dir . '/dir-inside');
51
        file_put_contents($dir . '/file.txt', '...');
52
53
        @rmdir($dir);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
54
        $this->assertTrue(file_exists($dir));
55
56
        $this->fileSystem->purgeDir($dir);
57
        $this->assertTrue(file_exists($dir));
58
59
        rmdir($dir);
60
        $this->assertFalse(file_exists($dir));
61
    }
62
63 View Code Duplication
    public function testPurgeDirOnNonExistingDir(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $dir = TEMP_DIR . '/not-created-dir';
66
        $this->assertFalse(file_exists($dir));
67
68
        $this->fileSystem->purgeDir($dir);
69
        $this->assertTrue(file_exists($dir));
70
    }
71
72
    public function testGetAbsolutePath(): void
73
    {
74
        $absoluteDir = $this->fileSystem->normalizePath(TEMP_DIR . '/relative-dir');
75
        mkdir($absoluteDir);
76
        $this->assertTrue(file_exists($absoluteDir));
77
78
        $absoluteFile = $absoluteDir . DIRECTORY_SEPARATOR . 'file.txt';
79
        file_put_contents($absoluteFile, '...');
80
        $this->assertTrue(file_exists($absoluteFile));
81
82
        $this->assertSame($absoluteDir, $this->fileSystem->getAbsolutePath($absoluteDir));
83
        $this->assertSame($absoluteDir . DIRECTORY_SEPARATOR . 'file.txt', $this->fileSystem->getAbsolutePath('file.txt', [$absoluteDir]));
84
85
        $this->assertSame(
86
            'someFile.txt',
87
            $this->fileSystem->getAbsolutePath('someFile.txt')
88
        );
89
90
        $testFile = DIRECTORY_SEPARATOR . 'someDir' . DIRECTORY_SEPARATOR . 'someDeeperFile.txt';
91
        $this->assertSame(
92
            $testFile,
93
            $this->fileSystem->getAbsolutePath($testFile)
94
        );
95
    }
96
97
    public function testIsDirEmpty(): void
98
    {
99
        $this->assertTrue($this->fileSystem->isDirEmpty(__DIR__ . '/FileSystemSource/EmptyDir'));
100
        $this->assertFalse($this->fileSystem->isDirEmpty(__DIR__ . '/FileSystemSource/NonEmptyDir'));
101
    }
102
}
103