1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-flow |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-flow/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-flow |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFlow\Test\Integration\Flow\File; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Node\FileNodeInterface; |
17
|
|
|
use Graze\DataFile\Node\LocalFile; |
18
|
|
|
use Graze\DataFlow\Flow; |
19
|
|
|
use Graze\DataFlow\Flow\File\MakeDirectory; |
20
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
use Mockery as m; |
23
|
|
|
|
24
|
|
|
class MakeDirectoryTest extends RealFileTestCase |
25
|
|
|
{ |
26
|
|
|
public function testMakeDirectoryNotOnLocalFileWillThrowAnException() |
27
|
|
|
{ |
28
|
|
|
$file = m::mock(FileNodeInterface::class); |
29
|
|
|
$flow = new MakeDirectory(); |
30
|
|
|
|
31
|
|
|
$this->expectException(InvalidArgumentException::class); |
32
|
|
|
|
33
|
|
|
$flow->flow($file); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testMakeDirectory() |
37
|
|
|
{ |
38
|
|
|
$file = $this->makeFile('makeDirectory/initial/file'); |
39
|
|
|
$flow = new MakeDirectory(); |
40
|
|
|
|
41
|
|
|
static::assertFalse(is_dir($file->getDirectory())); |
42
|
|
|
$output = $flow->flow($file); |
43
|
|
|
static::assertTrue(is_dir($output->getDirectory())); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function testStaticFlow() |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$file = $this->makeFile('makeDirectory/static/file'); |
49
|
|
|
$flow = Flow::makeDirectory(); |
50
|
|
|
|
51
|
|
|
static::assertFalse(is_dir($file->getDirectory())); |
52
|
|
|
$output = $flow->flow($file); |
53
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
54
|
|
|
static::assertTrue(is_dir($output->getDirectory())); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function testInvokeFlow() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$file = $this->makeFile('makeDirectory/invoke/file'); |
60
|
|
|
$flow = new MakeDirectory(); |
61
|
|
|
|
62
|
|
|
static::assertFalse(is_dir($file->getDirectory())); |
63
|
|
|
$output = call_user_func($flow, $file); |
64
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
65
|
|
|
static::assertTrue(is_dir($output->getDirectory())); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.