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\FileNodeCollection; |
17
|
|
|
use Graze\DataFile\Node\FileNodeInterface; |
18
|
|
|
use Graze\DataFlow\Flow; |
19
|
|
|
use Graze\DataFlow\Flow\File\Merge; |
20
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
21
|
|
|
use Graze\DataNode\NodeCollectionInterface; |
22
|
|
|
use InvalidArgumentException; |
23
|
|
|
use Mockery as m; |
24
|
|
|
|
25
|
|
|
class MergeTest extends RealFileTestCase |
26
|
|
|
{ |
27
|
|
|
public function testHeadNotOnLocalFileWillThrowAnException() |
28
|
|
|
{ |
29
|
|
|
$file = m::mock(NodeCollectionInterface::class); |
30
|
|
|
$flow = new Merge(m::mock(FileNodeInterface::class)); |
31
|
|
|
|
32
|
|
|
$this->expectException(InvalidArgumentException::class); |
33
|
|
|
|
34
|
|
|
$flow->flow($file); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function testMakeDirectory() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$file1 = $this->makeFile('merge/initial/file1', "line 1\nline 2\n"); |
40
|
|
|
$file2 = $this->makeFile('merge/initial/file2', "line 3\nline 4\n"); |
41
|
|
|
$merged = $this->makeFile('merge/initial/merged'); |
42
|
|
|
|
43
|
|
|
$flow = new Merge($merged); |
44
|
|
|
$collection = new FileNodeCollection([$file1, $file2]); |
45
|
|
|
|
46
|
|
|
$output = $flow->flow($collection); |
47
|
|
|
|
48
|
|
|
static::assertSame($output, $merged); |
49
|
|
|
static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function testStaticFlow() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$file1 = $this->makeFile('merge/static/file1', "line 1\nline 2\n"); |
55
|
|
|
$file2 = $this->makeFile('merge/static/file2', "line 3\nline 4\n"); |
56
|
|
|
$merged = $this->makeFile('merge/static/merged'); |
57
|
|
|
|
58
|
|
|
$flow = Flow::merge($merged); |
59
|
|
|
$collection = new FileNodeCollection([$file1, $file2]); |
60
|
|
|
|
61
|
|
|
$output = $flow->flow($collection); |
62
|
|
|
|
63
|
|
|
static::assertSame($output, $merged); |
64
|
|
|
static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
View Code Duplication |
public function testInvokeFlow() |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$file1 = $this->makeFile('merge/invoke/file1', "line 1\nline 2\n"); |
70
|
|
|
$file2 = $this->makeFile('merge/invoke/file2', "line 3\nline 4\n"); |
71
|
|
|
$merged = $this->makeFile('merge/invoke/merged'); |
72
|
|
|
|
73
|
|
|
$flow = new Merge($merged); |
74
|
|
|
$collection = new FileNodeCollection([$file1, $file2]); |
75
|
|
|
|
76
|
|
|
$output = call_user_func($flow, $collection); |
77
|
|
|
|
78
|
|
|
static::assertSame($output, $merged); |
79
|
|
|
static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.