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() |
|
|
|
|
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() |
|
|
|
|
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() |
|
|
|
|
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
|
|
|
|
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.