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\FileNode; |
17
|
|
|
use Graze\DataFlow\Flow; |
18
|
|
|
use Graze\DataFlow\Flow\File\MoveFile; |
19
|
|
|
use Graze\DataFlow\Test\MemoryFileTestCase; |
20
|
|
|
use Graze\DataNode\NodeInterface; |
21
|
|
|
use InvalidArgumentException; |
22
|
|
|
use Mockery as m; |
23
|
|
|
|
24
|
|
|
class MoveMemoryFileTest extends MemoryFileTestCase |
25
|
|
|
{ |
26
|
|
View Code Duplication |
public function testMoveFileNotOnLocalFileWillThrowAnException() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$file = m::mock(NodeInterface::class); |
29
|
|
|
$flow = new MoveFile(m::mock(FileNode::class)); |
30
|
|
|
|
31
|
|
|
$this->expectException(InvalidArgumentException::class); |
32
|
|
|
|
33
|
|
|
$flow->flow($file); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function testCopyFileCreatesANewFile() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$file = $this->makeFile('move/flow/source', 'some text'); |
39
|
|
|
$target = $this->makeFile('move/flow/target'); |
40
|
|
|
|
41
|
|
|
$flow = new MoveFile($target); |
42
|
|
|
|
43
|
|
|
$output = $flow->flow($file); |
44
|
|
|
|
45
|
|
|
static::assertSame($target, $output); |
46
|
|
|
static::assertInstanceOf(FileNode::class, $output); |
47
|
|
|
static::assertEquals(['some text'], $output->getContents()); |
48
|
|
|
static::assertFalse($file->exists(), "The original file should not exist"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
View Code Duplication |
public function testStaticFlow() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$file = $this->makeFile('move/static/source', 'some text'); |
54
|
|
|
$target = $this->makeFile('move/static/target'); |
55
|
|
|
|
56
|
|
|
$flow = Flow::moveFile($target); |
57
|
|
|
|
58
|
|
|
$output = $flow->flow($file); |
59
|
|
|
|
60
|
|
|
static::assertSame($target, $output); |
61
|
|
|
static::assertInstanceOf(FileNode::class, $output); |
62
|
|
|
static::assertEquals(['some text'], $output->getContents()); |
63
|
|
|
static::assertFalse($file->exists(), "The original file should still exist"); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testInvokeFlow() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$file = $this->makeFile('move/invoke/source', 'some text'); |
69
|
|
|
$target = $this->makeFile('move/invoke/target'); |
70
|
|
|
|
71
|
|
|
$flow = Flow::moveFile($target); |
72
|
|
|
|
73
|
|
|
$output = call_user_func($flow, $file); |
74
|
|
|
|
75
|
|
|
static::assertSame($target, $output); |
76
|
|
|
static::assertInstanceOf(FileNode::class, $output); |
77
|
|
|
static::assertEquals(['some text'], $output->getContents()); |
78
|
|
|
static::assertFalse($file->exists(), "The original file should still exist"); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testCopyFileWithDirectoryTargetWillUseOriginalFileName() |
82
|
|
|
{ |
83
|
|
|
$file = $this->makeFile('move/todir/source', 'some text'); |
84
|
|
|
$target = $this->makeFile('move/todir/target/'); |
85
|
|
|
|
86
|
|
|
$flow = Flow::copyFile($target); |
87
|
|
|
|
88
|
|
|
$output = $flow->flow($file); |
89
|
|
|
|
90
|
|
|
static::assertNotSame($target, $output); |
91
|
|
|
static::assertInstanceOf(FileNode::class, $output); |
92
|
|
|
static::assertEquals($file->getContents(), $output->getContents()); |
93
|
|
|
static::assertEquals('source', $output->getFilename()); |
94
|
|
|
static::assertEquals('move/todir/target/source', $output->getPath()); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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.