Passed
Push — master ( e9f016 )
by Nicolas
14:47
created

SchemaTest::itCanBeSerialized()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace ElevenLabs\Api;
3
4
use ElevenLabs\Api\Definition\RequestDefinition;
5
use ElevenLabs\Api\Definition\RequestDefinitions;
6
use PHPUnit\Framework\TestCase;
7
8
class SchemaTest extends TestCase
9
{
10
    /** @test */
11
    public function itCanResolveAnOperationIdFromAPathAndMethod()
12
    {
13
        $request = $this->prophesize(RequestDefinition::class);
14
        $request->getMethod()->willReturn('GET');
15
        $request->getPathTemplate()->willReturn('/api/pets/{id}');
16
        $request->getOperationId()->willReturn('getPet');
17
18
        $requests = $this->prophesize(RequestDefinitions::class);
19
        $requests->getIterator()->willReturn(new \ArrayIterator([$request->reveal()]));
20
21
        $schema = new Schema($requests->reveal());
22
23
        $operationId = $schema->findOperationId('GET', '/api/pets/1234');
24
25
        assertThat($operationId, equalTo('getPet'));
26
    }
27
28
    /** @test */
29
    public function itThrowAnExceptionWhenNoOperationIdCanBeResolved()
30
    {
31
        $this->expectException(\InvalidArgumentException::class);
32
        $this->expectExceptionMessage('Unable to resolve the operationId for path /api/pets/1234');
33
34
        $requests = $this->prophesize(RequestDefinitions::class);
35
        $requests->getIterator()->willReturn(new \ArrayIterator());
36
37
        $schema = new Schema($requests->reveal(), '/api');
38
        $schema->findOperationId('GET', '/api/pets/1234');
39
    }
40
41
    /** @test */
42
    public function itProvideARequestDefinition()
43
    {
44
        $request = $this->prophesize(RequestDefinition::class);
45
        $request->getMethod()->willReturn('GET');
46
        $request->getPathTemplate()->willReturn('/pets/{id}');
47
        $request->getOperationId()->willReturn('getPet');
48
49
        $requests = $this->prophesize(RequestDefinitions::class);
50
        $requests->getIterator()->willReturn(new \ArrayIterator([$request->reveal()]));
51
52
        $schema = new Schema($requests->reveal(), '/api');
53
        $actual = $schema->getRequestDefinition('getPet');
54
55
        assertThat($actual, equalTo($request->reveal()));
56
    }
57
58
    /** @test */
59
    public function itThrowAnExceptionWhenNoRequestDefinitionIsFound()
60
    {
61
        $this->expectException(\InvalidArgumentException::class);
62
        $this->expectExceptionMessage('Unable to get the request definition for getPet');
63
64
        $requests = $this->prophesize(RequestDefinitions::class);
65
        $requests->getIterator()->willReturn(new \ArrayIterator());
66
67
        $schema = new Schema($requests->reveal(), '/api');
68
        $schema->getRequestDefinition('getPet');
69
    }
70
71
    /** @test */
72
    public function itCanBeSerialized()
73
    {
74
        $requests = $this->prophesize(RequestDefinitions::class);
75
        $requests->getIterator()->willReturn(new \ArrayIterator());
76
77
        $schema = new Schema($requests->reveal());
78
        $serialized = serialize($schema);
79
80
        assertThat(unserialize($serialized), equalTo($schema));
81
    }
82
}
83