|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hateoas\Tests\Configuration\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use Hateoas\Configuration\Relation; |
|
6
|
|
|
use Hateoas\Configuration\RelationProvider as RelationProviderConfiguration; |
|
7
|
|
|
use Hateoas\Configuration\Provider\RelationProvider; |
|
8
|
|
|
use Hateoas\Tests\TestCase; |
|
9
|
|
|
use Prophecy\Argument; |
|
10
|
|
|
|
|
11
|
|
|
class RelationProviderTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function test() |
|
14
|
|
|
{ |
|
15
|
|
|
$relationProviders = array( |
|
16
|
|
|
new RelationProviderConfiguration('getRelations'), |
|
17
|
|
|
new RelationProviderConfiguration('Class:getRelations'), |
|
18
|
|
|
); |
|
19
|
|
|
$relations1 = array($relation1 = new Relation('foo')); |
|
20
|
|
|
$relations2 = array($relation2 = new Relation('bar')); |
|
21
|
|
|
|
|
22
|
|
|
$classMetadataProphecy = $this->prophesize('Hateoas\Configuration\Metadata\ClassMetadataInterface'); |
|
23
|
|
|
$classMetadataProphecy |
|
24
|
|
|
->getRelationProviders() |
|
25
|
|
|
->willReturn($relationProviders) |
|
26
|
|
|
; |
|
27
|
|
|
|
|
28
|
|
|
$metadataFactoryProphecy = $this->prophesize('Metadata\MetadataFactoryInterface'); |
|
29
|
|
|
$metadataFactoryProphecy |
|
30
|
|
|
->getMetadataForClass('stdClass') |
|
31
|
|
|
->willReturn($classMetadataProphecy->reveal()) |
|
32
|
|
|
; |
|
33
|
|
|
|
|
34
|
|
|
$resolverProphecy = $this->prophesize('Hateoas\Configuration\Provider\Resolver\RelationProviderResolverInterface'); |
|
35
|
|
|
$resolverProphecy |
|
36
|
|
|
->getRelationProvider(Argument::which('getName', 'getRelations'), Argument::any()) |
|
37
|
|
|
->willReturn(function () use ($relations1) { |
|
38
|
|
|
return $relations1; |
|
39
|
|
|
}) |
|
40
|
|
|
; |
|
41
|
|
|
$resolverProphecy |
|
42
|
|
|
->getRelationProvider(Argument::which('getName', 'Class:getRelations'), Argument::any()) |
|
43
|
|
|
->willReturn(function () use ($relations2) { |
|
44
|
|
|
return $relations2; |
|
45
|
|
|
}) |
|
46
|
|
|
; |
|
47
|
|
|
|
|
48
|
|
|
$relationProvider = new RelationProvider($metadataFactoryProphecy->reveal(), $resolverProphecy->reveal()); |
|
49
|
|
|
|
|
50
|
|
|
$object = new \StdClass(); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame([$relation1, $relation2], $relationProvider->getRelations($object)); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|