1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hateoas\Tests\Factory; |
4
|
|
|
|
5
|
|
|
use Hateoas\Configuration\Relation; |
6
|
|
|
use Hateoas\Factory\LinksFactory; |
7
|
|
|
use Hateoas\Model\Link; |
8
|
|
|
use Hateoas\Tests\TestCase; |
9
|
|
|
use JMS\Serializer\SerializationContext; |
10
|
|
|
|
11
|
|
|
class LinksFactoryTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function test() |
14
|
|
|
{ |
15
|
|
|
$object = new \StdClass(); |
16
|
|
|
$context = SerializationContext::create(); |
17
|
|
|
|
18
|
|
|
$relations = array( |
19
|
|
|
new Relation('self', '/users/1'), |
20
|
|
|
new Relation('manager', '/users/2'), |
21
|
|
|
); |
22
|
|
|
$link = new Link('', ''); |
23
|
|
|
|
24
|
|
|
$relationsRepositoryProphecy = $this->prophesize('Hateoas\Configuration\RelationsRepository'); |
25
|
|
|
$relationsRepositoryProphecy |
26
|
|
|
->getRelations($object) |
27
|
|
|
->willReturn($relations) |
28
|
|
|
->shouldBeCalledTimes(1) |
29
|
|
|
; |
30
|
|
|
$linkFactoryProphecy = $this->prophesize('Hateoas\Factory\LinkFactory'); |
31
|
|
|
$linkFactoryProphecy |
32
|
|
|
->createLink($object, $relations[1]) |
33
|
|
|
->willReturn($link) |
34
|
|
|
->shouldBeCalledTimes(1) |
35
|
|
|
; |
36
|
|
|
$exclusionManagerProphecy = $this->prophesize('Hateoas\Serializer\ExclusionManager'); |
37
|
|
|
$exclusionManagerProphecy |
38
|
|
|
->shouldSkipLink($object, $relations[0], $context) |
39
|
|
|
->willReturn(true) |
40
|
|
|
->shouldBeCalledTimes(1) |
41
|
|
|
; |
42
|
|
|
$exclusionManagerProphecy |
43
|
|
|
->shouldSkipLink($object, $relations[1], $context) |
44
|
|
|
->willReturn(false) |
45
|
|
|
->shouldBeCalledTimes(1) |
46
|
|
|
; |
47
|
|
|
|
48
|
|
|
$linksFactory = new LinksFactory( |
49
|
|
|
$relationsRepositoryProphecy->reveal(), |
50
|
|
|
$linkFactoryProphecy->reveal(), |
51
|
|
|
$exclusionManagerProphecy->reveal() |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$links = $linksFactory->create($object, $context); |
55
|
|
|
|
56
|
|
|
$this->assertCount(1, $links); |
57
|
|
|
$this->assertContains($link, $links); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|