1 | <?php |
||
27 | class FileNodeTest extends TestCase |
||
28 | { |
||
29 | /** |
||
30 | * @return mixed Really a Filesystem|MockInterface but coding standards get confused |
||
31 | */ |
||
32 | private function getFilesystem() |
||
33 | { |
||
34 | $fileSystem = m::mock(Filesystem::class); |
||
35 | $fileSystem->shouldReceive('getAdapter') |
||
36 | ->andReturn(m::mock(AdapterInterface::class)); |
||
37 | $fileSystem->shouldReceive('getConfig') |
||
38 | ->andReturn(null); |
||
39 | return $fileSystem; |
||
40 | } |
||
41 | |||
42 | public function testInstanceOf() |
||
43 | { |
||
44 | $fileSystem = $this->getFilesystem(); |
||
45 | $file = new FileNode($fileSystem, 'not/nop'); |
||
46 | |||
47 | static::assertInstanceOf(FileNodeInterface::class, $file); |
||
48 | static::assertInstanceOf(FormatAwareInterface::class, $file); |
||
49 | static::assertInstanceOf(CompressionAwareInterface::class, $file); |
||
50 | static::assertInstanceOf(EncodingAwareInterface::class, $file); |
||
51 | } |
||
52 | |||
53 | public function testEmptyFileWillReturnEmptyArrayForGetContents() |
||
54 | { |
||
55 | $fileSystem = $this->getFilesystem(); |
||
56 | $file = new FileNode($fileSystem, 'not/exists'); |
||
57 | |||
58 | $fileSystem->shouldReceive('has') |
||
59 | ->with('not/exists') |
||
60 | ->andReturn(false); |
||
61 | |||
62 | static::assertEquals([], $file->getContents()); |
||
63 | } |
||
64 | |||
65 | public function testWhenCopyFailsItRaisesAnException() |
||
66 | { |
||
67 | $fileSystem = $this->getFilesystem(); |
||
68 | $localFile = new FileNode($fileSystem, 'some/random'); |
||
69 | |||
70 | $newPath = new FileNode($fileSystem, 'some/target'); |
||
71 | |||
72 | $fileSystem->shouldReceive('copy') |
||
73 | ->with($localFile->getPath(), $newPath->getPath()) |
||
74 | ->andReturn(false); |
||
75 | |||
76 | $this->expectException(CopyFailedException::class); |
||
77 | |||
78 | $localFile->copy($newPath->getPath()); |
||
79 | } |
||
80 | |||
81 | public function testSetFileSystemUpdatesTheFileSystem() |
||
104 | } |
||
105 |