Code Duplication    Length = 66-66 lines in 2 locations

tests/integration/Flow/File/CopyFilesTest.php 1 location

@@ 24-89 (lines=66) @@
21
use InvalidArgumentException;
22
use Mockery as m;
23
24
class CopyFilesTest extends MemoryFileTestCase
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

tests/integration/Flow/File/MoveFilesTest.php 1 location

@@ 24-89 (lines=66) @@
21
use InvalidArgumentException;
22
use Mockery as m;
23
24
class MoveFilesTest extends MemoryFileTestCase
25
{
26
    public function testMoveFilesNotOnLocalFileWillThrowAnException()
27
    {
28
        $target = $this->makeFile('moves/flow/target/');
29
        $flow = new MoveFiles($target);
30
31
        $this->expectException(InvalidArgumentException::class);
32
33
        $flow->flow(m::mock(NodeInterface::class));
34
    }
35
36
    public function testMoveFilesWithATargetThatIsNotADirectoryWillThrowAnException()
37
    {
38
        $target = $this->makeFile('moves/flow/target');
39
40
        $this->expectException(InvalidArgumentException::class);
41
42
        new MoveFiles($target);
43
    }
44
45
    public function testMoveFilesCreatesANewFile()
46
    {
47
        $file = $this->makeFile('moves/flow/source/file', 'some text');
48
        $target = $this->makeFile('moves/flow/target/');
49
50
        $flow = new MoveFiles($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('moves/flow/target/file', $output->getAll()[0]->getPath());
57
        static::assertFalse($file->exists(), "The original file should not exist");
58
    }
59
60
    public function testStaticFlow()
61
    {
62
        $file = $this->makeFile('moves/static/source/file', 'some text');
63
        $target = $this->makeFile('moves/static/target/');
64
65
        $flow = Flow::moveFiles($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('moves/static/target/file', $output->getAll()[0]->getPath());
72
        static::assertFalse($file->exists(), "The original file should not exist");
73
    }
74
75
    public function testInvokeFlow()
76
    {
77
        $file = $this->makeFile('moves/invoke/source/file', 'some text');
78
        $target = $this->makeFile('moves/invoke/target/');
79
80
        $flow = Flow::moveFiles($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('moves/invoke/target/file', $output->getAll()[0]->getPath());
87
        static::assertFalse($file->exists(), "The original file should not exist");
88
    }
89
}
90