Completed
Pull Request — master (#3)
by Harry
05:31
created

FileNodeTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testEmptyFileWillReturnEmptyArrayForGetContents() 0 11 1
A testWhenCopyFailsItRaisesAnException() 0 15 1
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\Integration\Node;
15
16
use Graze\DataFile\Modify\Exception\CopyFailedException;
17
use Graze\DataFile\Node\FileNode;
18
use Graze\DataFile\Test\TestCase;
19
use League\Flysystem\FilesystemInterface;
20
use Mockery as m;
21
22
class FileNodeTest extends TestCase
23
{
24
    public function testEmptyFileWillReturnEmptyArrayForGetContents()
25
    {
26
        $fileSystem = m::mock(FilesystemInterface::class);
27
        $file = new FileNode($fileSystem, 'not/exists');
28
29
        $fileSystem->shouldReceive('has')
30
                   ->with('not/exists')
31
                   ->andReturn(false);
32
33
        static::assertEquals([], $file->getContents());
34
    }
35
36
    public function testWhenCopyFailsItRaisesAnException()
37
    {
38
        $fileSystem = m::mock(FilesystemInterface::class);
39
        $localFile = new FileNode($fileSystem, 'some/random');
40
41
        $newPath = new FileNode($fileSystem, 'some/target');
42
43
        $fileSystem->shouldReceive('copy')
44
                   ->with($localFile->getPath(), $newPath->getPath())
45
                   ->andReturn(false);
46
47
        $this->expectException(CopyFailedException::class);
48
49
        $localFile->copy($newPath->getPath());
50
    }
51
}
52