Completed
Push — master ( 9bc3b7...a15851 )
by Harry
02:46
created

MakeDirectoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 51.61 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 32
loc 62
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testCanMakeDirectory() 11 11 1
A testCanCallMakeDirectoryWithAnExistingFolder() 10 10 1
A testCanMakeDirectoryWithSpecificUMode() 11 11 1
A testCreatingADirectoryWithoutPermissionThrowsAnException() 0 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Graze\DataFile\Test\Integration\Modify;
4
5
use Graze\DataFile\Modify\Exception\MakeDirectoryFailedException;
6
use Graze\DataFile\Modify\MakeDirectory;
7
use Graze\DataFile\Node\LocalFile;
8
use Graze\DataFile\Test\FileTestCase;
9
use Mockery as m;
10
11
class MakeDirectoryTest extends FileTestCase
12
{
13
    /**
14
     * @var MakeDirectory
15
     */
16
    private $maker;
17
18
    public function setUp()
19
    {
20
        $this->maker = new MakeDirectory();
21
    }
22
23 View Code Duplication
    public function testCanMakeDirectory()
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...
24
    {
25
        $file = new LocalFile(static::$dir . 'test/file');
26
27
        static::assertFalse(file_exists($file->getDirectory()));
28
29
        $retFile = $this->maker->makeDirectory($file);
30
31
        static::assertTrue(file_exists($file->getDirectory()));
32
        static::assertSame($file, $retFile);
33
    }
34
35 View Code Duplication
    public function testCanMakeDirectoryWithSpecificUMode()
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...
36
    {
37
        $file = new LocalFile(static::$dir . 'umode_test/file');
38
39
        static::assertFalse(file_exists($file->getDirectory()));
40
41
        $retFile = $this->maker->makeDirectory($file, MakeDirectory::VISIBILITY_PUBLIC);
42
43
        static::assertEquals(0755, fileperms($file->getDirectory()) & 0777);
44
        static::assertSame($retFile, $file);
45
    }
46
47 View Code Duplication
    public function testCanCallMakeDirectoryWithAnExistingFolder()
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...
48
    {
49
        $file = new LocalFile(static::$dir . 'no_dir_file');
50
51
        static::assertTrue(file_exists($file->getDirectory()));
52
53
        $retFile = $this->maker->makeDirectory($file);
54
55
        static::assertSame($retFile, $file);
56
    }
57
58
    public function testCreatingADirectoryWithoutPermissionThrowsAnException()
59
    {
60
        $validDirectory = new LocalFile(static::$dir . 'valid/dir.test');
61
62
        $this->maker->makeDirectory($validDirectory, MakeDirectory::VISIBILITY_PRIVATE);
63
        static::assertTrue(file_exists($validDirectory->getDirectory()));
64
        static::assertEquals(0700, fileperms($validDirectory->getDirectory()) & 0777);
65
66
        $invalidDirectory = new LocalFile(static::$dir . 'valid/invalid/dir.test');
67
68
        $this->expectException(MakedirectoryFailedException::class);
69
70
        $this->maker->makeDirectory($invalidDirectory);
71
    }
72
}
73