|
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\LocalFile; |
|
17
|
|
|
use Graze\DataFlow\Flow; |
|
18
|
|
|
use Graze\DataFlow\Flow\File\ReplaceText; |
|
19
|
|
|
use Graze\DataFlow\Test\RealFileTestCase; |
|
20
|
|
|
use Graze\DataNode\NodeInterface; |
|
21
|
|
|
use InvalidArgumentException; |
|
22
|
|
|
use Mockery as m; |
|
23
|
|
|
|
|
24
|
|
|
class ReplaceTextTest extends RealFileTestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testReplaceTextNotOnLocalFileWillThrowAnException() |
|
27
|
|
|
{ |
|
28
|
|
|
$file = m::mock(NodeInterface::class); |
|
29
|
|
|
$flow = new ReplaceText('text', 'bananas'); |
|
30
|
|
|
|
|
31
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
32
|
|
|
|
|
33
|
|
|
$flow->flow($file); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testReplaceText() |
|
37
|
|
|
{ |
|
38
|
|
|
$file = $this->makeFile('replaceText/initial/from', 'some text'); |
|
39
|
|
|
$flow = new ReplaceText('text', 'bananas'); |
|
40
|
|
|
|
|
41
|
|
|
$output = $flow->flow($file); |
|
42
|
|
|
|
|
43
|
|
|
static::assertNotSame($file, $output); |
|
44
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
|
45
|
|
|
static::assertEquals(['some bananas'], $output->getContents()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testStaticFlow() |
|
49
|
|
|
{ |
|
50
|
|
|
$file = $this->makeFile('replaceText/static/from', 'some text'); |
|
51
|
|
|
$flow = Flow::replaceText('text', 'bananas'); |
|
52
|
|
|
|
|
53
|
|
|
$output = $flow->flow($file); |
|
54
|
|
|
|
|
55
|
|
|
static::assertNotSame($file, $output); |
|
56
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
|
57
|
|
|
static::assertEquals(['some bananas'], $output->getContents()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testInvokeFlow() |
|
61
|
|
|
{ |
|
62
|
|
|
$file = $this->makeFile('replaceText/invoke/from', 'some text'); |
|
63
|
|
|
$flow = new ReplaceText('text', 'bananas'); |
|
64
|
|
|
|
|
65
|
|
|
$output = call_user_func($flow, $file); |
|
66
|
|
|
|
|
67
|
|
|
static::assertNotSame($file, $output); |
|
68
|
|
|
static::assertInstanceOf(LocalFile::class, $output); |
|
69
|
|
|
static::assertEquals(['some bananas'], $output->getContents()); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|