1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hateoas\Tests\Configuration; |
4
|
|
|
|
5
|
|
|
use Hateoas\Tests\TestCase; |
6
|
|
|
use Hateoas\Configuration\Relation; |
7
|
|
|
use Hateoas\Configuration\RelationsRepository; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
|
10
|
|
|
class RelationsRepositoryTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testEmptyGetRelations() |
13
|
|
|
{ |
14
|
|
|
$relationsRepository = new RelationsRepository( |
15
|
|
|
$this->prophesizeMetadataFactory()->reveal(), |
16
|
|
|
$this->prophesizeRelationProvider()->reveal() |
17
|
|
|
); |
18
|
|
|
$object = new \StdClass(); |
19
|
|
|
|
20
|
|
|
$this->assertEmpty($relationsRepository->getRelations($object)); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testMetadataFactoryRelations() |
24
|
|
|
{ |
25
|
|
|
$relations = array( |
26
|
|
|
new Relation('', ''), |
27
|
|
|
new Relation('', ''), |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$classMetadataProphecy = $this->prophesize('Hateoas\Configuration\Metadata\ClassMetadataInterface'); |
31
|
|
|
$classMetadataProphecy |
32
|
|
|
->getRelations() |
33
|
|
|
->willReturn($relations) |
34
|
|
|
->shouldBeCalledTimes(1) |
35
|
|
|
; |
36
|
|
|
$metadataFactoryProphecy = $this->prophesizeMetadataFactory(); |
37
|
|
|
$metadataFactoryProphecy |
38
|
|
|
->getMetadataForClass('stdClass') |
39
|
|
|
->willReturn($classMetadataProphecy->reveal()) |
40
|
|
|
; |
41
|
|
|
$relationsRepository = new RelationsRepository( |
42
|
|
|
$metadataFactoryProphecy->reveal(), |
43
|
|
|
$this->prophesizeRelationProvider()->reveal() |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this->assertSame($relations, $relationsRepository->getRelations(new \StdClass())); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testRelationProviderRelations() |
50
|
|
|
{ |
51
|
|
|
$relations = array( |
52
|
|
|
new Relation('', ''), |
53
|
|
|
new Relation('', ''), |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$object = new \StdClass(); |
57
|
|
|
|
58
|
|
|
$relationsRepository = new RelationsRepository( |
59
|
|
|
$this->prophesizeMetadataFactory()->reveal(), |
60
|
|
|
$this->prophesizeRelationProvider($relations, $object)->reveal() |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$this->assertSame($relations, $relationsRepository->getRelations($object)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function prophesizeRelationProvider($relations = array(), $object = null) |
67
|
|
|
{ |
68
|
|
|
$relationProviderProphecy = $this->prophesize('Hateoas\Configuration\Provider\RelationProvider'); |
69
|
|
|
$relationProviderProphecy |
70
|
|
|
->getRelations($object ?: Argument::any()) |
71
|
|
|
->willReturn($relations) |
72
|
|
|
; |
73
|
|
|
|
74
|
|
|
return $relationProviderProphecy; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
private function prophesizeMetadataFactory() |
78
|
|
|
{ |
79
|
|
|
return $this->prophesize('Metadata\MetadataFactoryInterface'); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|