1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\Yproximite\WannaSpeakBundle\Api; |
6
|
|
|
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
use Symfony\Component\Mime\Part\DataPart; |
10
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface; |
11
|
|
|
use Yproximite\WannaSpeakBundle\Api\Sounds; |
12
|
|
|
use Yproximite\WannaSpeakBundle\Api\SoundsInterface; |
13
|
|
|
use Yproximite\WannaSpeakBundle\HttpClientInterface; |
14
|
|
|
|
15
|
|
|
class SoundsSpec extends ObjectBehavior |
16
|
|
|
{ |
17
|
|
|
public function it_is_initializable() |
18
|
|
|
{ |
19
|
|
|
$this->shouldHaveType(Sounds::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function let(HttpClientInterface $client, ResponseInterface $response): void |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$this->beConstructedWith($client); |
25
|
|
|
|
26
|
|
|
// Since we are in spec, the response content will always be the, see PHPUnit tests for real response asserting. |
27
|
|
|
$response |
28
|
|
|
->toArray() |
29
|
|
|
->willReturn(['error' => null, 'data' => [/* ... */]]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function it_should_list(HttpClientInterface $client, ResponseInterface $response) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$client |
35
|
|
|
->request(SoundsInterface::API, 'list', []) |
36
|
|
|
->shouldBeCalled() |
37
|
|
|
->willReturn($response); |
38
|
|
|
|
39
|
|
|
$this |
40
|
|
|
->list() |
41
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function it_should_upload_from_path(HttpClientInterface $client, ResponseInterface $response) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$client |
|
|
|
|
47
|
|
|
->request( |
48
|
|
|
SoundsInterface::API, |
49
|
|
|
'upload', |
50
|
|
|
Argument::that(function ($args) { |
51
|
|
|
return $args['sound'] instanceof DataPart |
52
|
|
|
&& 'the name' === $args['name']; |
53
|
|
|
}) |
54
|
|
|
) |
55
|
|
|
->shouldBeCalled() |
56
|
|
|
->willReturn($response); |
57
|
|
|
|
58
|
|
|
$this |
|
|
|
|
59
|
|
|
->upload(__DIR__.'/../../../../tests/fixtures/callee.mp3', 'the name') |
60
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function it_should_upload_from_file(HttpClientInterface $client, ResponseInterface $response) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$client |
|
|
|
|
66
|
|
|
->request( |
67
|
|
|
SoundsInterface::API, |
68
|
|
|
'upload', |
69
|
|
|
Argument::that(function ($args) { |
70
|
|
|
return $args['sound'] instanceof DataPart |
71
|
|
|
&& 'the name' === $args['name']; |
72
|
|
|
}) |
73
|
|
|
) |
74
|
|
|
->shouldBeCalled() |
75
|
|
|
->willReturn($response); |
76
|
|
|
|
77
|
|
|
$file = new \SplFileInfo(__DIR__.'/../../../../tests/fixtures/callee.mp3'); |
78
|
|
|
|
79
|
|
|
$this |
|
|
|
|
80
|
|
|
->upload($file, 'the name') |
81
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function it_should_delete(HttpClientInterface $client, ResponseInterface $response) |
85
|
|
|
{ |
86
|
|
|
$client |
87
|
|
|
->request(SoundsInterface::API, 'delete', [ |
88
|
|
|
'name' => 'the name', |
89
|
|
|
]) |
90
|
|
|
->shouldBeCalled() |
91
|
|
|
->willReturn($response); |
92
|
|
|
|
93
|
|
|
$this |
94
|
|
|
->delete('the name') |
95
|
|
|
->shouldBe(['error' => null, 'data' => [/* ... */]]); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
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.