4
4
5
5
use Symfony \Cmf \Bundle \RoutingAutoBundle \AutoRoute \UrlGenerator ;
6
6
use Symfony \Cmf \Bundle \RoutingAutoBundle \Tests \Unit \BaseTestCase ;
7
+ use Prophecy \Argument ;
7
8
8
9
class UrlGeneratorTest extends BaseTestCase
9
10
{
10
11
protected $ driver ;
11
12
protected $ serviceRegistry ;
12
13
protected $ tokenProviders = array ();
14
+ protected $ urlContext ;
13
15
14
16
public function setUp ()
15
17
{
16
18
parent ::setUp ();
17
19
18
- $ this ->metadataFactory = $ this ->prophet ->prophesize (
19
- 'Metadata\MetadataFactoryInterface '
20
- );
21
- $ this ->metadata = $ this ->prophet ->prophesize (
22
- 'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Mapping\ClassMetadata '
23
- );
24
- $ this ->driver = $ this ->prophet ->prophesize (
25
- 'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Driver\DriverInterface '
26
- );
27
- $ this ->serviceRegistry = $ this ->prophet ->prophesize (
28
- 'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ServiceRegistry '
29
- );
30
- $ this ->tokenProvider = $ this ->prophet ->prophesize (
31
- 'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\TokenProviderInterface '
32
- );
20
+ $ this ->metadataFactory = $ this ->prophesize ('Metadata\MetadataFactoryInterface ' );
21
+ $ this ->metadata = $ this ->prophesize ('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Mapping\ClassMetadata ' );
22
+ $ this ->driver = $ this ->prophesize ('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Adapter\AdapterInterface ' );
23
+ $ this ->serviceRegistry = $ this ->prophesize ('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ServiceRegistry ' );
24
+ $ this ->tokenProvider = $ this ->prophesize ('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\TokenProviderInterface ' );
25
+ $ this ->urlContext = $ this ->prophesize ('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext ' );
33
26
34
27
$ this ->urlGenerator = new UrlGenerator (
35
28
$ this ->metadataFactory ->reveal (),
@@ -46,8 +39,9 @@ public function provideGenerateUrl()
46
39
'/this/is/foobar_value/a/url ' ,
47
40
array (
48
41
'token_the_first ' => array (
49
- 'provider ' => 'foobar_provider ' ,
42
+ 'name ' => 'foobar_provider ' ,
50
43
'value ' => 'foobar_value ' ,
44
+ 'options ' => array (),
51
45
),
52
46
),
53
47
),
@@ -56,16 +50,19 @@ public function provideGenerateUrl()
56
50
'/that/was/foobar_value/a/url ' ,
57
51
array (
58
52
'token_the_first ' => array (
59
- 'provider ' => 'foobar_provider ' ,
53
+ 'name ' => 'foobar_provider ' ,
60
54
'value ' => 'foobar_value ' ,
55
+ 'options ' => array (),
61
56
),
62
57
'this ' => array (
63
- 'provider ' => 'barfoo_provider ' ,
58
+ 'name ' => 'barfoo_provider ' ,
64
59
'value ' => 'that ' ,
60
+ 'options ' => array (),
65
61
),
66
62
'is ' => array (
67
- 'provider ' => 'dobar_provider ' ,
63
+ 'name ' => 'dobar_provider ' ,
68
64
'value ' => 'was ' ,
65
+ 'options ' => array (),
69
66
),
70
67
),
71
68
),
@@ -78,33 +75,35 @@ public function provideGenerateUrl()
78
75
public function testGenerateUrl ($ urlSchema , $ expectedUrl , $ tokenProviderConfigs )
79
76
{
80
77
$ document = new \stdClass ;
78
+ $ this ->urlContext ->getSubjectObject ()->willReturn ($ document );
81
79
$ this ->driver ->getRealClassName ('stdClass ' )
82
80
->willReturn ('ThisIsMyStandardClass ' );
83
81
84
82
$ this ->metadataFactory ->getMetadataForClass ('ThisIsMyStandardClass ' )
85
83
->willReturn ($ this ->metadata );
86
84
87
- $ this ->metadata ->getTokenProviderConfigs ()
85
+ $ this ->metadata ->getTokenProviders ()
88
86
->willReturn ($ tokenProviderConfigs );
89
87
90
88
$ this ->metadata ->getUrlSchema ()
91
89
->willReturn ($ urlSchema );
92
90
93
91
foreach ($ tokenProviderConfigs as $ tokenName => $ tokenProviderConfig ) {
94
- $ providerName = $ tokenProviderConfig ['provider ' ];
92
+ $ providerName = $ tokenProviderConfig ['name ' ];
95
93
96
- $ this ->tokenProviders [$ providerName ] = $ this ->prophet -> prophesize (
94
+ $ this ->tokenProviders [$ providerName ] = $ this ->prophesize (
97
95
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\TokenProviderInterface '
98
96
);
99
97
100
- $ this ->serviceRegistry ->getTokenProvider ($ tokenProviderConfig ['provider ' ])
98
+ $ this ->serviceRegistry ->getTokenProvider ($ tokenProviderConfig ['name ' ])
101
99
->willReturn ($ this ->tokenProviders [$ providerName ]);
102
100
103
- $ this ->tokenProviders [$ providerName ]->getValue ( $ document , $ tokenProviderConfig )
101
+ $ this ->tokenProviders [$ providerName ]->provideValue ( $ this -> urlContext , $ tokenProviderConfig[ ' options ' ] )
104
102
->willReturn ($ tokenProviderConfig ['value ' ]);
103
+ $ this ->tokenProviders [$ providerName ]->configureOptions (Argument::type ('Symfony\Component\OptionsResolver\OptionsResolverInterface ' ))->shouldBeCalled ();
105
104
}
106
105
107
- $ res = $ this ->urlGenerator ->generateUrl ($ document );
106
+ $ res = $ this ->urlGenerator ->generateUrl ($ this -> urlContext -> reveal () );
108
107
109
108
$ this ->assertEquals ($ expectedUrl , $ res );
110
109
}
0 commit comments