Completed
Push — master ( 10e391...d5f2dc )
by Harry
06:06
created

testWhenCopyFailsItRaisesAnException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/data-file
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-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Unit\Node;
15
16
use Graze\DataFile\Format\FormatAwareInterface;
17
use Graze\DataFile\Modify\Compress\CompressionAwareInterface;
18
use Graze\DataFile\Modify\Encoding\EncodingAwareInterface;
19
use Graze\DataFile\Modify\Exception\CopyFailedException;
20
use Graze\DataFile\Node\FileNode;
21
use Graze\DataFile\Node\FileNodeInterface;
22
use Graze\DataFile\Test\TestCase;
23
use League\Flysystem\FilesystemInterface;
24
use Mockery as m;
25
26
class FileNodeTest extends TestCase
27
{
28
    public function testInstanceOf()
29
    {
30
        $fileSystem = m::mock(FilesystemInterface::class);
31
        $file = new FileNode($fileSystem, 'not/nop');
32
33
        static::assertInstanceOf(FileNodeInterface::class, $file);
34
        static::assertInstanceOf(FormatAwareInterface::class, $file);
35
        static::assertInstanceOf(CompressionAwareInterface::class, $file);
36
        static::assertInstanceOf(EncodingAwareInterface::class, $file);
37
    }
38
39
    public function testEmptyFileWillReturnEmptyArrayForGetContents()
40
    {
41
        $fileSystem = m::mock(FilesystemInterface::class);
42
        $file = new FileNode($fileSystem, 'not/exists');
43
44
        $fileSystem->shouldReceive('has')
45
                   ->with('not/exists')
46
                   ->andReturn(false);
47
48
        static::assertEquals([], $file->getContents());
49
    }
50
51
    public function testWhenCopyFailsItRaisesAnException()
52
    {
53
        $fileSystem = m::mock(FilesystemInterface::class);
54
        $localFile = new FileNode($fileSystem, 'some/random');
55
56
        $newPath = new FileNode($fileSystem, 'some/target');
57
58
        $fileSystem->shouldReceive('copy')
59
                   ->with($localFile->getPath(), $newPath->getPath())
60
                   ->andReturn(false);
61
62
        $this->expectException(CopyFailedException::class);
63
64
        $localFile->copy($newPath->getPath());
65
    }
66
}
67