Completed
Push — develop ( 2993ce...48a3ec )
by Mike
09:32
created

FlySystemFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testCreateLocalFilesystemWithoutCache() 0 14 1
A testCreateLocalFilesystemWithCache() 0 10 1
A testUnsupportedScheme() 0 8 1
A testFlyFinderIsRegistered() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @copyright 2010-2018 Mike van Riel<[email protected]>
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Parser;
16
17
use Flyfinder\Specification\InPath;
18
use League\Flysystem\Adapter\AbstractAdapter;
19
use Mockery as m;
20
use phpDocumentor\Dsn;
21
22
/**
23
 * @coversDefaultClass \phpDocumentor\Parser\FlySystemFactory
24
 */
25
final class FlySystemFactoryTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
26
{
27
    /** @var FlySystemFactory */
28
    private $fixture;
29
30
    /** @var m\Mock */
31
    private $mountManagerMock;
32
33
    /** @var m\Mock */
34
    private $filesystemMock;
35
36
    /** @var Dsn */
37
    private $dsn;
38
39
    protected function setUp()
40
    {
41
        $this->mountManagerMock = m::mock('League\Flysystem\MountManager');
42
        $this->filesystemMock = m::mock('League\Flysystem\Filesystem');
43
        $this->dsn = new Dsn('file:///tmp');
44
        $this->fixture = new FlySystemFactory($this->mountManagerMock);
45
    }
46
47
    /**
48
     * @covers ::__construct
49
     * @covers ::create
50
     * @covers ::<private>
51
     */
52
    public function testCreateLocalFilesystemWithoutCache()
53
    {
54
        $this->mountManagerMock->shouldReceive('mountFilesystem')->once();
55
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andThrow('\LogicException');
56
57
        $result = $this->fixture->create($this->dsn);
58
59
        $this->assertInstanceOf('League\Flysystem\Filesystem', $result);
60
61
        /** @var AbstractAdapter $adapter */
62
        $adapter = $result->getAdapter();
63
        $pathPrefix = $adapter->getPathPrefix();
64
        $this->assertEquals(realpath('/tmp') . DIRECTORY_SEPARATOR, $pathPrefix);
65
    }
66
67
    /**
68
     * @covers ::__construct
69
     * @covers ::create
70
     * @covers ::<private>
71
     */
72
    public function testCreateLocalFilesystemWithCache()
73
    {
74
        $this->mountManagerMock->shouldReceive('mountFilesystem')->never();
75
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andReturn($this->filesystemMock);
76
        $this->filesystemMock->shouldReceive('addPlugin');
77
78
        $result = $this->fixture->create($this->dsn);
79
80
        $this->assertInstanceOf('League\Flysystem\Filesystem', $result);
81
    }
82
83
    /**
84
     * @covers ::__construct
85
     * @covers ::create
86
     * @covers ::<private>
87
     * @expectedException \InvalidArgumentException
88
     */
89
    public function testUnsupportedScheme()
90
    {
91
        $this->mountManagerMock->shouldReceive('mountFilesystem')->never();
92
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andThrow('\LogicException');
93
        $dsn = new Dsn('git+http://github.com');
94
95
        $this->fixture->create($dsn);
96
    }
97
98
    /**
99
     * @covers ::__construct
100
     * @covers ::create
101
     * @covers ::<private>
102
     */
103
    public function testFlyFinderIsRegistered()
104
    {
105
        $this->mountManagerMock->shouldReceive('mountFilesystem')->once();
106
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andThrow('\LogicException');
107
        $fileSystem = $this->fixture->create($this->dsn);
108
109
        $fileSystem->find(new InPath(new \Flyfinder\Path('a')));
110
    }
111
}
112