Completed
Push — master ( 3e9c3d...99411a )
by Hugo
22s queued 11s
created

SoundsTest::testUploadFileAsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yproximite\WannaSpeakBundle\Tests\Api;
6
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\HttpClient\Response\MockResponse;
9
use Yproximite\WannaSpeakBundle\Api\Sounds;
10
use Yproximite\WannaSpeakBundle\Tests\HttpClientTestTrait;
11
12
class SoundsTest extends TestCase
13
{
14
    use HttpClientTestTrait;
15
16
    public function testList(): void
17
    {
18
        $sounds = new Sounds(
19
            $this->createHttpClient(new MockResponse(
20
                (string) json_encode([
21
                    'error' => null,
22
                    'data'  => [
23
                        'files' => [
24
                            'item1',
25
                            'item2',
26
                            'item3',
27
                        ],
28
                    ],
29
                ])
30
            ))
31
        );
32
33
        static::assertSame(
34
            [
35
                'error' => null,
36
                'data'  => [
37
                    'files' => [
38
                        'item1',
39
                        'item2',
40
                        'item3',
41
                    ],
42
                ],
43
            ],
44
            $sounds->list()
45
        );
46
    }
47
48
    public function testListWithLinks(): void
49
    {
50
        $sounds = new Sounds(
51
            $this->createHttpClient(new MockResponse(
52
                (string) json_encode([
53
                    'error' => null,
54
                    'data'  => [
55
                        'files' => [
56
                            ['item1', 'https://.../path/to/item1.mp3'],
57
                            ['item2', 'https://.../path/to/item2.mp3'],
58
                            ['item3', 'https://.../path/to/item3.mp3'],
59
                        ],
60
                    ],
61
                ])
62
            ))
63
        );
64
65
        static::assertSame(
66
            [
67
                'error' => null,
68
                'data'  => [
69
                    'files' => [
70
                        ['item1', 'https://.../path/to/item1.mp3'],
71
                        ['item2', 'https://.../path/to/item2.mp3'],
72
                        ['item3', 'https://.../path/to/item3.mp3'],
73
                    ],
74
                ],
75
            ],
76
            $sounds->list(['link' => true])
77
        );
78
    }
79
80 View Code Duplication
    public function testUploadFileAsPath(): void
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...
81
    {
82
        $this->expectNotToPerformAssertions();
83
84
        $sounds = new Sounds(
85
            $this->createHttpClient(new MockResponse(
86
                (string) json_encode([
87
                    'error' => null,
88
                    'data'  => [
89
                        'ok'   => true,
90
                        'name' => 'thename',
91
                    ],
92
                ])
93
            ))
94
        );
95
96
        $sounds->upload(__DIR__.'/../fixtures/callee.mp3', 'the name');
97
    }
98
99 View Code Duplication
    public function testUploadFileAsSplFileInfo(): void
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...
100
    {
101
        $this->expectNotToPerformAssertions();
102
103
        $sounds = new Sounds(
104
            $this->createHttpClient(new MockResponse(
105
                (string) json_encode([
106
                    'error' => null,
107
                    'data'  => [
108
                        'ok'   => true,
109
                        'name' => 'thename',
110
                    ],
111
                ])
112
            ))
113
        );
114
115
        $splFileInfo = new \SplFileInfo(__DIR__.'/../fixtures/callee.mp3');
116
117
        $sounds->upload($splFileInfo, 'the name');
118
    }
119
120
    public function testDelete(): void
121
    {
122
        $this->expectNotToPerformAssertions();
123
124
        $sounds = new Sounds(
125
            $this->createHttpClient(new MockResponse(
126
                (string) json_encode([
127
                    'error' => null,
128
                    'data'  => [
129
                        'ok' => true,
130
                    ],
131
                ])
132
            ))
133
        );
134
135
        $sounds->delete('the name');
136
    }
137
}
138