Completed
Push — develop ( 114abf...08add9 )
by Jaap
03:44
created

FlySystemFactoryTest::testUnsupportedScheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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