ServerFileSystemTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFilesInDirectory() 0 6 1
A testDeleteFilesInDirectoryRecursively() 0 21 2
A testGetFilesInDirectoryIsRecursiveAndAlphabetical() 0 8 1
1
<?php
2
3
namespace Partnermarketing\FileSystemBundle\Tests\Unit\ServerFileSystem;
4
5
use Partnermarketing\FileSystemBundle\ServerFileSystem\ServerFileSystem;
6
7
class ServerFileSystemTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testGetFilesInDirectory()
10
    {
11
        $files = ServerFileSystem::getFilesInDirectory(__DIR__);
12
13
        $this->assertCount(1, $files);
14
    }
15
16
    public function testGetFilesInDirectoryIsRecursiveAndAlphabetical()
17
    {
18
        $files = ServerFileSystem::getFilesInDirectory(__DIR__  . '/../');
19
20
        $this->assertCount(6, $files);
21
        $this->assertStringEndsWith('Unit/Adapter/LocalStorageTest.php', $files[0]);
22
        $this->assertStringEndsWith('Unit/Factory/FileSystemFactoryTest.php', $files[3]);
23
    }
24
25
    public function testDeleteFilesInDirectoryRecursively()
26
    {
27
        $dir = __DIR__ . '/deleteFilesInDirectoryRecursively/';
28
29
        if (!is_dir($dir)) {
30
            mkdir($dir);
31
        }
32
        file_put_contents($dir . '1.txt', '1');
33
        file_put_contents($dir . '2.txt', '2');
34
        mkdir($dir . 'subdir');
35
        file_put_contents($dir . 'subdir/3.txt', '3');
36
        file_put_contents($dir . 'subdir/4.txt', '4');
37
38
        $filesBefore = ServerFileSystem::getFilesInDirectory($dir);
39
        $this->assertCount(4, $filesBefore);
40
41
        $files = ServerFileSystem::deleteFilesInDirectoryRecursively($dir);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $files is correct as \Partnermarketing\FileSy...ectoryRecursively($dir) (which targets Partnermarketing\FileSys...nDirectoryRecursively()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$files is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
43
        $filesAfter = ServerFileSystem::getFilesInDirectory($dir);
44
        $this->assertCount(0, $filesAfter);
45
    }
46
}
47