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
|
|
|
|