CopyFilesTest::testStaticFlow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 14
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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\DataFlow\Flow;
18
use Graze\DataFlow\Flow\File\CopyFiles;
19
use Graze\DataFlow\Test\MemoryFileTestCase;
20
use Graze\DataNode\NodeInterface;
21
use InvalidArgumentException;
22
use Mockery as m;
23
24 View Code Duplication
class CopyFilesTest extends MemoryFileTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
25
{
26
    public function testCopyFilesNotOnLocalFileWillThrowAnException()
27
    {
28
        $target = $this->makeFile('copys/flow/target/');
29
        $flow = new CopyFiles($target);
30
31
        $this->expectException(InvalidArgumentException::class);
32
33
        $flow->flow(m::mock(NodeInterface::class));
34
    }
35
36
    public function testCopyFilesWithATargetThatIsNotADirectoryWillThrowAnException()
37
    {
38
        $target = $this->makeFile('copys/flow/target');
39
40
        $this->expectException(InvalidArgumentException::class);
41
42
        new CopyFiles($target);
43
    }
44
45
    public function testCopyFilesCreatesANewFile()
46
    {
47
        $file = $this->makeFile('copys/flow/source/file', 'some text');
48
        $target = $this->makeFile('copys/flow/target/');
49
50
        $flow = new CopyFiles($target);
51
52
        $output = $flow->flow(new FileNodeCollection([$file]));
53
54
        static::assertInstanceOf(FileNodeCollection::class, $output);
55
        static::assertEquals(1, $output->count());
56
        static::assertEquals('copys/flow/target/file', $output->getAll()[0]->getPath());
57
        static::assertTrue($file->exists(), "The original file should still exist");
58
    }
59
60
    public function testStaticFlow()
61
    {
62
        $file = $this->makeFile('copys/static/source/file', 'some text');
63
        $target = $this->makeFile('copys/static/target/');
64
65
        $flow = Flow::copyFiles($target);
66
67
        $output = $flow->flow(new FileNodeCollection([$file]));
68
69
        static::assertInstanceOf(FileNodeCollection::class, $output);
70
        static::assertEquals(1, $output->count());
71
        static::assertEquals('copys/static/target/file', $output->getAll()[0]->getPath());
72
        static::assertTrue($file->exists(), "The original file should still exist");
73
    }
74
75
    public function testInvokeFlow()
76
    {
77
        $file = $this->makeFile('copys/invoke/source/file', 'some text');
78
        $target = $this->makeFile('copys/invoke/target/');
79
80
        $flow = Flow::copyFiles($target);
81
82
        $output = call_user_func($flow, new FileNodeCollection([$file]));
83
84
        static::assertInstanceOf(FileNodeCollection::class, $output);
85
        static::assertEquals(1, $output->count());
86
        static::assertEquals('copys/invoke/target/file', $output->getAll()[0]->getPath());
87
        static::assertTrue($file->exists(), "The original file should still exist");
88
    }
89
}
90