1
|
|
|
<?php |
2
|
|
|
namespace ElevenLabs\Api\Definition; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
class RequestDefinitionTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
/** @test */ |
9
|
|
|
public function itCanBeSerialized() |
10
|
|
|
{ |
11
|
|
|
$requestDefinition = new RequestDefinition( |
12
|
|
|
'GET', |
13
|
|
|
'getFoo', |
14
|
|
|
'/foo/{id}', |
15
|
|
|
new Parameters([]), |
16
|
|
|
['application/json'], |
17
|
|
|
[] |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
$serialized = serialize($requestDefinition); |
21
|
|
|
|
22
|
|
|
assertThat(unserialize($serialized), self::equalTo($requestDefinition)); |
23
|
|
|
} |
24
|
|
|
/** @test */ |
25
|
|
|
public function itProvideAResponseDefinition() |
26
|
|
|
{ |
27
|
|
|
$responseDefinition = $this->prophesize(ResponseDefinition::class); |
28
|
|
|
$responseDefinition->getStatusCode()->willReturn(200); |
29
|
|
|
|
30
|
|
|
$requestDefinition = new RequestDefinition( |
31
|
|
|
'GET', |
32
|
|
|
'getFoo', |
33
|
|
|
'/foo/{id}', |
34
|
|
|
new Parameters([]), |
35
|
|
|
['application/json'], |
36
|
|
|
[$responseDefinition->reveal()] |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
assertThat($requestDefinition->getResponseDefinition(200), self::isInstanceOf(ResponseDefinition::class)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** @test */ |
43
|
|
|
public function itProvideAResponseDefinitionUsingDefaultValue() |
44
|
|
|
{ |
45
|
|
|
$statusCodes = [200, 'default']; |
46
|
|
|
$responseDefinitions = []; |
47
|
|
|
foreach ($statusCodes as $statusCode) { |
48
|
|
|
$responseDefinition = $this->prophesize(ResponseDefinition::class); |
49
|
|
|
$responseDefinition->getStatusCode()->willReturn($statusCode); |
50
|
|
|
$responseDefinitions[] = $responseDefinition->reveal(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$requestDefinition = new RequestDefinition( |
54
|
|
|
'GET', |
55
|
|
|
'getFoo', |
56
|
|
|
'/foo/{id}', |
57
|
|
|
new Parameters([]), |
58
|
|
|
['application/json'], |
59
|
|
|
$responseDefinitions |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
assertThat($requestDefinition->getResponseDefinition(500), self::isInstanceOf(ResponseDefinition::class)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** @test */ |
66
|
|
|
public function itThrowAnExceptionWhenNoResponseDefinitionIsFound() |
67
|
|
|
{ |
68
|
|
|
$this->expectException(\InvalidArgumentException::class); |
69
|
|
|
$this->expectExceptionMessage('No response definition for GET /foo/{id} is available for status code 200'); |
70
|
|
|
|
71
|
|
|
$requestDefinition = new RequestDefinition( |
72
|
|
|
'GET', |
73
|
|
|
'getFoo', |
74
|
|
|
'/foo/{id}', |
75
|
|
|
new Parameters([]), |
76
|
|
|
['application/json'], |
77
|
|
|
[] |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$requestDefinition->getResponseDefinition(200); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|