1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ElevenLabs\Api\Service\Tests\Resource; |
6
|
|
|
|
7
|
|
|
use ElevenLabs\Api\Service\Pagination\Pagination; |
8
|
|
|
use ElevenLabs\Api\Service\Resource\Collection; |
9
|
|
|
use ElevenLabs\Api\Service\Resource\ResourceInterface; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class CollectionTest. |
14
|
|
|
*/ |
15
|
|
|
class CollectionTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** @test */ |
18
|
|
|
public function itIsAResource() |
19
|
|
|
{ |
20
|
|
|
$resource = new Collection([], [], []); |
21
|
|
|
|
22
|
|
|
assertThat($resource, isInstanceOf(ResourceInterface::class)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** @test */ |
26
|
|
|
public function itProvideDataAndMeta() |
27
|
|
|
{ |
28
|
|
|
$data = [['foo' => 'bar']]; |
29
|
|
|
$meta = ['headers' => ['bat' => 'baz']]; |
30
|
|
|
$resource = new Collection($data, $meta, $data); |
31
|
|
|
|
32
|
|
|
$this->assertSame($data, $resource->getData()); |
33
|
|
|
$this->assertSame($meta, $resource->getMeta()); |
34
|
|
|
$this->assertSame($data, $resource->getBody()); |
35
|
|
|
$this->assertFalse($resource->hasPagination()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** @test */ |
39
|
|
|
public function itProvideAPagination() |
40
|
|
|
{ |
41
|
|
|
$pagination = new Pagination(1, 1, 1, 1); |
42
|
|
|
$resource = new Collection([], [], [], $pagination); |
43
|
|
|
|
44
|
|
|
$this->assertSame($pagination, $resource->getPagination()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** @test */ |
48
|
|
|
public function itIsTraversable() |
49
|
|
|
{ |
50
|
|
|
$data = [ |
51
|
|
|
['value' => 'foo'], |
52
|
|
|
['value' => 'bar'], |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
$resource = new Collection($data, [], $data); |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf(\Traversable::class, $resource); |
58
|
|
|
$this->assertContains($data[0], $resource); |
59
|
|
|
$this->assertContains($data[1], $resource); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|