1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Knp\RadBundle\Resource\Resolver; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
|
7
|
|
|
class OptionsBasedSpec extends ObjectBehavior |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param Symfony\Component\DependencyInjection\ContainerInterface $container |
11
|
|
|
* @param Knp\RadBundle\Resource\Resolver\OptionsBased\ArgumentResolver $argumentResolver |
12
|
|
|
* @param Symfony\Component\HttpFoundation\Request $request |
|
|
|
|
13
|
|
|
* @param spec\Knp\RadBundle\Resource\Resolver\CheeseRepository $cheeseRepository |
14
|
|
|
* @param stdClass $cheese |
|
|
|
|
15
|
|
|
*/ |
16
|
|
|
function let($container, $argumentResolver, $cheeseRepository) |
17
|
|
|
{ |
18
|
|
|
$this->beConstructedWith($container, $argumentResolver); |
19
|
|
|
$container->get('orm.cheese_repository')->willReturn($cheeseRepository); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param stdClass $cheese |
24
|
|
|
*/ |
25
|
|
|
function it_should_resolve_resource($request, $argumentResolver, $container, $cheese, $cheeseRepository) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$argumentResolver->resolveArgument($request, array('value' => 'normandie'))->willReturn('normandie'); |
28
|
|
|
$argumentResolver->resolveArgument($request, array('name' => 'slug'))->willReturn('neufchatel'); |
29
|
|
|
|
30
|
|
|
$cheeseRepository->findByRegionAndSlug('normandie', 'neufchatel')->shouldBeCalled()->willReturn($cheese); |
31
|
|
|
|
32
|
|
|
$this |
33
|
|
|
->resolveResource($request, array( |
34
|
|
|
'service' => 'orm.cheese_repository', |
35
|
|
|
'method' => 'findByRegionAndSlug', |
36
|
|
|
'arguments' => array( |
37
|
|
|
array('value' => 'normandie'), |
38
|
|
|
array('name' => 'slug'), |
39
|
|
|
) |
40
|
|
|
)) |
41
|
|
|
->shouldReturn($cheese) |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_should_throw_resolution_failure_when_resolved_resource_is_null($request, $argumentResolver, $cheeseRepository) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$argumentResolver->resolveArgument($request, array('name' => 'slug'))->willReturn('neufchatel'); |
48
|
|
|
$cheeseRepository->findBySlug('neufchatel')->willReturn(null); |
49
|
|
|
|
50
|
|
|
$this->shouldThrow()->duringResolveResource($request, array( |
51
|
|
|
'service' => 'orm.cheese_repository', |
52
|
|
|
'method' => 'findBySlug', |
53
|
|
|
'arguments' => array( |
54
|
|
|
array('name' => 'slug') |
55
|
|
|
) |
56
|
|
|
)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_should_throw_exception_when_resouce_has_extra_options($request) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$this->shouldThrow()->duringResolveResource($request, array( |
62
|
|
|
'extra' => 'the extra value', |
63
|
|
|
'service' => 'orm.cheese_repository', |
64
|
|
|
'method' => 'findByRegionAndSlug', |
65
|
|
|
'arguments' => array( |
66
|
|
|
array('value' => 'normandie'), |
67
|
|
|
array('name' => 'slug'), |
68
|
|
|
), |
69
|
|
|
)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function it_should_throw_exception_when_resource_is_missing_service_option($request) |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$this->shouldThrow()->duringResolveResource($request, array( |
75
|
|
|
'method' => 'findByRegionAndSlug', |
76
|
|
|
'arguments' => array( |
77
|
|
|
array('value' => 'normandie'), |
78
|
|
|
array('name' => 'slug'), |
79
|
|
|
), |
80
|
|
|
)); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function it_should_throw_exception_when_resource_is_missing_method_option($request) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$this->shouldThrow()->duringResolveResource($request, array( |
86
|
|
|
'service' => 'orm.cheese_repository', |
87
|
|
|
'arguments' => array( |
88
|
|
|
array('name' => 'slug'), |
89
|
|
|
), |
90
|
|
|
)); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
class CheeseRepository |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
public function findBySlug($slug) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function findByRegionAndSlug($region, $slug) |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.