Completed
Push — 6.0 ( c6d21a...a43f83 )
by yun
15:10 queued 11:06
created

FilesystemTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace think\tests;
4
5
use League\Flysystem\Adapter\NullAdapter;
6
use League\Flysystem\AdapterInterface;
7
use Mockery as m;
8
use Mockery\MockInterface;
9
use org\bovigo\vfs\vfsStream;
10
use org\bovigo\vfs\vfsStreamDirectory;
11
use PHPUnit\Framework\TestCase;
12
use think\App;
13
use think\Cache;
14
use think\cache\driver\File;
15
use think\Config;
16
use think\Container;
17
use think\Filesystem;
18
use think\filesystem\Driver;
19
use think\filesystem\driver\Local;
20
21
class FilesystemTest extends TestCase
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class FilesystemTest
Loading history...
22
{
23
    /** @var App|MockInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
24
    protected $app;
25
26
    /** @var Filesystem */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
27
    protected $filesystem;
28
29
    /** @var Config|MockInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
30
    protected $config;
31
32
    /** @var vfsStreamDirectory */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
33
    protected $root;
34
35
    protected function setUp()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setUp()
Loading history...
36
    {
37
        $this->app = m::mock(App::class)->makePartial();
38
        Container::setInstance($this->app);
39
        $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app);
40
        $this->config = m::mock(Config::class);
41
        $this->config->shouldReceive('get')->with('filesystem.default')->andReturn('local');
42
        $this->app->shouldReceive('get')->with('config')->andReturn($this->config);
43
        $this->filesystem = new Filesystem($this->app);
44
45
        $this->root = vfsStream::setup('rootDir');
46
    }
47
48
    protected function tearDown(): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tearDown()
Loading history...
49
    {
50
        m::close();
51
    }
52
53
    public function testDisk()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testDisk()
Loading history...
54
    {
55
        $this->config->shouldReceive('get')->once()->with('filesystem.disks.local')->andReturn([
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on think\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        $this->config->/** @scrutinizer ignore-call */ 
56
                       shouldReceive('get')->once()->with('filesystem.disks.local')->andReturn([

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...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
56
            'type' => 'local',
57
            'root' => $this->root->url(),
58
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
59
60
        $this->config->shouldReceive('get')->once()->with('filesystem.disks.foo')->andReturn([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
61
            'type' => 'local',
62
            'root' => $this->root->url(),
63
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
64
65
        $this->assertInstanceOf(Local::class, $this->filesystem->disk());
66
67
        $this->assertInstanceOf(Local::class, $this->filesystem->disk('foo'));
68
    }
69
70
    public function testCache()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testCache()
Loading history...
71
    {
72
        $this->config->shouldReceive('get')->once()->with('filesystem.disks.local')->andReturn([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
73
            'type'  => 'local',
74
            'root'  => $this->root->url(),
75
            'cache' => true,
76
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
77
78
        $this->assertInstanceOf(Local::class, $this->filesystem->disk());
79
80
        $this->config->shouldReceive('get')->once()->with('filesystem.disks.cache')->andReturn([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
81
            'type'  => NullDriver::class,
82
            'root'  => $this->root->url(),
83
            'cache' => [
84
                'store' => 'flysystem',
85
            ],
86
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
87
88
        $cache = m::mock(Cache::class);
89
90
        $cacheDriver = m::mock(File::class);
91
92
        $cache->shouldReceive('store')->once()->with('flysystem')->andReturn($cacheDriver);
93
94
        $this->app->shouldReceive('get')->once()->with('cache')->andReturn($cache);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on think\App. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        $this->app->/** @scrutinizer ignore-call */ 
95
                    shouldReceive('get')->once()->with('cache')->andReturn($cache);

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...
95
96
        $cacheDriver->shouldReceive('get')->with('flysystem')->once()->andReturn(null);
97
98
        $cacheDriver->shouldReceive('set')->withAnyArgs();
99
100
        $this->filesystem->disk('cache')->put('test.txt', 'aa');
0 ignored issues
show
Bug introduced by
The method put() does not exist on think\filesystem\Driver. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
        $this->filesystem->disk('cache')->/** @scrutinizer ignore-call */ put('test.txt', 'aa');
Loading history...
101
    }
102
103
    public function testPutFile()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testPutFile()
Loading history...
104
    {
105
        $root = vfsStream::setup('rootDir', null, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
106
            'foo.jpg' => 'hello',
107
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
108
109
        $this->config->shouldReceive('get')->once()->with('filesystem.disks.local')->andReturn([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
110
            'type'  => NullDriver::class,
111
            'root'  => $root->url(),
112
            'cache' => true,
113
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
114
115
        $file = m::mock(\think\File::class);
116
117
        $file->shouldReceive('hashName')->with(null)->once()->andReturn('foo.jpg');
118
119
        $file->shouldReceive('getRealPath')->once()->andReturn($root->getChild('foo.jpg')->url());
120
121
        $this->filesystem->putFile('test', $file);
0 ignored issues
show
Bug introduced by
The method putFile() does not exist on think\Filesystem. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

121
        $this->filesystem->/** @scrutinizer ignore-call */ 
122
                           putFile('test', $file);
Loading history...
122
    }
123
}
124
125
class NullDriver extends Driver
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class NullDriver
Loading history...
126
{
127
    protected function createAdapter(): AdapterInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function createAdapter()
Loading history...
128
    {
129
        return new NullAdapter();
130
    }
131
}
132