Completed
Push — develop ( 0b8425...c51867 )
by Jaap
15s queued 11s
created

Infrastructure/FlySystemFactoryTest.php (1 issue)

calls to non-existent methods.

Bug Major

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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-2018 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 League\Flysystem\Adapter\AbstractAdapter;
17
use Mockery as m;
18
use phpDocumentor\DomainModel\Dsn;
19
20
/**
21
 * Test case for FilesystemFactory
22
 * @coversDefaultClass phpDocumentor\Infrastructure\FlySystemFactory
23
 */
24
class FlySystemFactoryTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
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
        /** @var AbstractAdapter $adapter */
61
        $adapter = $result->getAdapter();
62
        $pathPrefix = $adapter->getPathPrefix();
63
        $this->assertEquals(realpath('/tmp') . DIRECTORY_SEPARATOR, $pathPrefix);
64
    }
65
66
    /**
67
     * @covers ::__construct
68
     * @covers ::create
69
     * @covers ::<private>
70
     */
71
    public function testCreateLocalFilesystemWithCache()
72
    {
73
        $this->mountManagerMock->shouldReceive('mountFilesystem')->never();
74
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andReturn($this->filesystemMock);
75
        $this->filesystemMock->shouldReceive('addPlugin');
76
77
        $result = $this->fixture->create($this->dsn);
78
79
        $this->assertInstanceOf('League\Flysystem\Filesystem', $result);
80
    }
81
82
    /**
83
     * @covers ::__construct
84
     * @covers ::create
85
     * @covers ::<private>
86
     * @expectedException \InvalidArgumentException
87
     */
88
    public function testUnsupportedScheme()
89
    {
90
        $this->mountManagerMock->shouldReceive('mountFilesystem')->never();
91
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andThrow('\LogicException');
92
        $dsn = new Dsn('git+http://github.com');
93
94
        $this->fixture->create($dsn);
95
    }
96
97
    /**
98
     * @covers ::__construct
99
     * @covers ::create
100
     * @covers ::<private>
101
     */
102
    public function testFlyFinderIsRegistered()
103
    {
104
        $this->mountManagerMock->shouldReceive('mountFilesystem')->once();
105
        $this->mountManagerMock->shouldReceive('getFilesystem')->once()->andThrow('\LogicException');
106
        $fileSystem = $this->fixture->create($this->dsn);
107
108
        $fileSystem->find(new InPath(new \Flyfinder\Path('a')));
0 ignored issues
show
The method find() does not seem to exist on object<League\Flysystem\FilesystemInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
109
    }
110
}
111