Completed
Push — master ( d5f2dc...b1b515 )
by Harry
03:55
created

FilesystemWrapperTest::testInstanceOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
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\FileSystem;
15
16
use Graze\DataFile\Node\FileSystem\FilesystemWrapper;
17
use Graze\DataFile\Node\FileSystem\FilesystemWrapperInterface;
18
use Graze\DataFile\Test\TestCase;
19
use InvalidArgumentException;
20
use League\Flysystem\AdapterInterface;
21
use League\Flysystem\Filesystem;
22
use League\Flysystem\FilesystemInterface;
23
use League\Flysystem\Handler;
24
use League\Flysystem\PluginInterface;
25
use Mockery as m;
26
27
class FilesystemWrapperTest extends TestCase
28
{
29
    public function testInstanceOf()
30
    {
31
        $filesystem = m::mock(FilesystemInterface::class);
32
        $wrapper = new FilesystemWrapper($filesystem);
33
34
        static::assertInstanceOf(FilesystemWrapperInterface::class, $wrapper);
35
        static::assertNotInstanceOf(FilesystemWrapperInterface::class, $filesystem);
36
    }
37
38
    public function testGetAdapter()
39
    {
40
        $filesystem = m::mock(Filesystem::class);
41
        $adapter = m::mock(AdapterInterface::class);
42
        $filesystem->shouldReceive('getAdapter')
43
                   ->andReturn($adapter);
44
        $wrapper = new FilesystemWrapper($filesystem);
45
46
        static::assertSame($adapter, $wrapper->getAdapter());
47
    }
48
49
    public function testGetAdapterWithANonFileSystemWillThrowAnException()
50
    {
51
        $filesystem = m::mock(FileSystemInterface::class);
52
        $wrapper = new FilesystemWrapper($filesystem);
53
54
        static::expectException(InvalidArgumentException::class);
55
        $wrapper->getAdapter();
56
    }
57
58
    public function testAllMethodsGetPassedToFileSystem()
59
    {
60
        $fileSystem = m::mock(FilesystemInterface::class);
61
        $wrapper = new FilesystemWrapper($fileSystem);
62
63
        $methods = [
64
            'has'           => ['some/path'],
65
            'read'          => ['some/path'],
66
            'readStream'    => ['some/path'],
67
            'listContents'  => ['some/path', false],
68
            'getMetadata'   => ['some/path'],
69
            'getSize'       => ['some/path'],
70
            'getMimetype'   => ['some/path'],
71
            'getTimestamp'  => ['some/path'],
72
            'getVisibility' => ['some/path'],
73
            'write'         => ['some/path', 'contents', []],
74
            'writeStream'   => ['some/path', 'resource', []],
75
            'update'        => ['some/path', 'contents', []],
76
            'updateStream'  => ['some/path', 'resource', []],
77
            'rename'        => ['some/path', 'some/newpath'],
78
            'copy'          => ['some/path', 'some/newpath'],
79
            'delete'        => ['some/path'],
80
            'deleteDir'     => ['some/path'],
81
            'createDir'     => ['some/path', []],
82
            'setVisibility' => ['some/path', 'public'],
83
            'put'           => ['some/path', 'contents', []],
84
            'putStream'     => ['some/path', 'resource', []],
85
            'readAndDelete' => ['some/path'],
86
            'get'           => ['some/path', m::mock(Handler::class)],
87
            'addPlugin'     => [m::mock(PluginInterface::class)],
88
        ];
89
90
        foreach ($methods as $method => $args) {
91
            $fileSystem->shouldReceive($method)
92
                       ->withArgs($args)
93
                       ->once();
94
            call_user_func_array([$wrapper, $method], $args);
95
        }
96
    }
97
}
98