testCopyFileWithDirectoryTargetWillUseOriginalFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
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\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()
0 ignored issues
show
Duplication introduced by
This method 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...
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()
0 ignored issues
show
Duplication introduced by
This method 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...
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()
0 ignored issues
show
Duplication introduced by
This method 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...
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()
0 ignored issues
show
Duplication introduced by
This method 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...
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