Completed
Pull Request — master (#16)
by frey
02:26
created

AdapterTest::testUpdateStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Freyo\Flysystem\QcloudCOSv3\Tests;
4
5
use League\Flysystem\Config;
6
use PHPUnit\Framework\TestCase;
7
use Freyo\Flysystem\QcloudCOSv3\Adapter;
8
9
class AdapterTest extends TestCase
10
{
11
    public function Provider()
12
    {
13
        $config = [
14
            'protocol' => 'http',
15
            'domain' => 'your-domain',
16
            'app_id' => 'your-app-id',
17
            'secret_id' => 'your-secret-id',
18
            'secret_key' => 'your-secret-key',
19
            'timeout' => 60,
20
            'bucket' => 'your-bucket-name',
21
            'debug' => true,
22
        ];
23
24
        $adapter = new Adapter($config);
25
26
        return [
27
            [$adapter, $config],
28
        ];
29
    }
30
31
    /**
32
     * @dataProvider Provider
33
     */
34
    public function testWrite($adapter)
0 ignored issues
show
Unused Code introduced by
The parameter $adapter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        //$this->assertTrue((bool)$adapter->write('foo/foo.md', 'content', new Config(['insertOnly' => 0])));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
        //$this->assertFalse((bool)$adapter->write('foo/foo.md', uniqid(), new Config(['insertOnly' => 1])));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
    }
39
40
    /**
41
     * @dataProvider Provider
42
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
43
     */
44 View Code Duplication
    public function testWriteStream($adapter)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $temp = tmpfile();
47
        fwrite($temp, "writing to tempfile");
48
        $this->assertTrue((bool)$adapter->writeStream('foo/bar.md', $temp, new Config(['insertOnly' => 0])));
49
        fclose($temp);
50
        
51
        $temp = tmpfile();
52
        fwrite($temp, uniqid());
53
        $this->assertFalse((bool)$adapter->writeStream('foo/bar.md', $temp, new Config(['insertOnly' => 1])));
54
        fclose($temp);
55
    }
56
    
57
    /**
58
     * @dataProvider Provider
59
     */
60
    public function testUpdate($adapter)
0 ignored issues
show
Unused Code introduced by
The parameter $adapter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        //$this->assertTrue((bool)$adapter->update('foo/bar.md', uniqid(), new Config(['insertOnly' => 0])));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
        //$this->assertFalse((bool)$adapter->update('foo/bar.md', uniqid(), new Config(['insertOnly' => 1])));
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
    }
65
    
66
    /**
67
     * @dataProvider Provider
68
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
69
     */
70 View Code Duplication
    public function testUpdateStream($adapter)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $temp = tmpfile();
73
        fwrite($temp, "writing to tempfile");
74
        $this->assertTrue((bool)$adapter->updateStream('foo/bar.md', $temp, new Config(['insertOnly' => 0])));
75
        fclose($temp);
76
        
77
        $temp = tmpfile();
78
        fwrite($temp, uniqid());
79
        $this->assertFalse((bool)$adapter->updateStream('foo/bar.md', $temp, new Config(['insertOnly' => 1])));
80
        fclose($temp);
81
    }
82
83
    /**
84
     * @dataProvider Provider
85
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
86
     */
87
    public function testRename($adapter)
88
    {
89
        $this->assertTrue($adapter->rename('foo/foo.md', 'foo/rename.md'));
90
        $this->assertFalse($adapter->rename('foo/notexist.md', 'foo/notexist.md'));
91
    }
92
    
93
    /**
94
     * @dataProvider Provider
95
     */
96
    public function testCopy($adapter)
0 ignored issues
show
Unused Code introduced by
The parameter $adapter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98
        //$this->assertTrue($adapter->copy('foo/bar.md', 'foo/copy.md'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
99
        //$this->assertFalse($adapter->copy('foo/notexist.md', 'foo/notexist.md'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
100
    }
101
102
    /**
103
     * @dataProvider Provider
104
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
105
     */
106
    public function testDelete($adapter)
107
    {
108
        $this->assertTrue($adapter->delete('foo/rename.md'));
109
        $this->assertFalse($adapter->delete('foo/notexist.md'));
110
    }
111
    
112
    /**
113
     * @dataProvider Provider
114
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
115
     */
116
    public function testCreateDir($adapter)
117
    {
118
        $this->assertTrue((bool)$adapter->createDir('bar', new Config()));
119
        $this->assertFalse((bool)$adapter->createDir('bar', new Config()));
120
    }
121
122
    /**
123
     * @dataProvider Provider
124
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
125
     */
126
    public function testDeleteDir($adapter)
127
    {
128
        $this->assertTrue($adapter->deleteDir('bar'));
129
        $this->assertFalse($adapter->deleteDir('notexist'));
130
    }
131
132
    /**
133
     * @dataProvider Provider
134
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
135
     */
136
    public function testSetVisibility($adapter)
137
    {
138
        $this->assertTrue($adapter->setVisibility('foo/copy.md', 'private'));
139
    }
140
141
    /**
142
     * @dataProvider Provider
143
     */
144
    public function testHas($adapter)
145
    {
146
        //$this->assertTrue($adapter->has('foo/bar.md'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147
        $this->assertFalse($adapter->has('foo/noexist.md'));
148
    }
149
    
150
    /**
151
     * @dataProvider Provider
152
     */
153
    public function testRead($adapter)
0 ignored issues
show
Unused Code introduced by
The parameter $adapter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
154
    {
155
        //$this->assertArrayHasKey('contents', $adapter->read('foo/bar.md'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
156
    }
157
158
    /**
159
     * @dataProvider Provider
160
     */
161
    public function testGetUrl($adapter, $config)
162
    {
163
        $this->assertSame(
164
            $config['protocol'] . '://' . $config['domain'] . '/foo/bar.md',
165
            $adapter->getUrl('foo/bar.md')
166
        );
167
    }
168
169
    /**
170
     * @dataProvider Provider
171
     */
172
    public function testReadStream($adapter)
0 ignored issues
show
Unused Code introduced by
The parameter $adapter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
    {
174
        //$this->assertSame(
175
        //    stream_get_contents(fopen($adapter->getUrl('foo/bar.md'), 'r')),
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
176
        //    stream_get_contents($adapter->readStream('foo/bar.md')['stream'])
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
177
        //);
178
    }
179
180
    /**
181
     * @dataProvider Provider
182
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
183
     */
184
    public function testListContents($adapter)
185
    {
186
        $this->assertArrayHasKey('infos', $adapter->listContents('foo'));
187
    }
188
189
    /**
190
     * @dataProvider Provider
191
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
192
     */
193
    public function testGetMetadata($adapter)
194
    {
195
        $this->assertArrayHasKey('access_url', $adapter->getMetadata('foo/bar.md'));
196
    }
197
198
    /**
199
     * @dataProvider Provider
200
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
201
     */
202
    public function testGetSize($adapter)
203
    {
204
        $this->assertArrayHasKey('size', $adapter->getSize('foo/bar.md'));
205
    }
206
    
207
    /**
208
     * @dataProvider Provider
209
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
210
     */
211
    public function testGetMimetype($adapter)
212
    {
213
        $this->assertNotSame(['mimetype' => ''], $adapter->getMimetype('foo/bar.md'));
214
    }
215
216
    /**
217
     * @dataProvider Provider
218
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
219
     */
220
    public function testGetTimestamp($adapter)
221
    {
222
        $this->assertNotSame(['timestamp' => 0], $adapter->getTimestamp('foo/bar.md'));
223
    }
224
225
    /**
226
     * @dataProvider Provider
227
     * @expectedException \Freyo\Flysystem\QcloudCOSv3\Exceptions\RuntimeException
228
     */
229
    public function testGetVisibility($adapter)
230
    {
231
        $this->assertSame(['visibility' => 'private'], $adapter->getVisibility('foo/copy.md'));
232
    }
233
}