Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 62c4f53

Browse files
committed
Fixed UrlGenerator test
1 parent f401226 commit 62c4f53

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

Tests/Unit/AutoRoute/UrlGeneratorTest.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,25 @@
44

55
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlGenerator;
66
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
7+
use Prophecy\Argument;
78

89
class UrlGeneratorTest extends BaseTestCase
910
{
1011
protected $driver;
1112
protected $serviceRegistry;
1213
protected $tokenProviders = array();
14+
protected $urlContext;
1315

1416
public function setUp()
1517
{
1618
parent::setUp();
1719

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');
3326

3427
$this->urlGenerator = new UrlGenerator(
3528
$this->metadataFactory->reveal(),
@@ -46,8 +39,9 @@ public function provideGenerateUrl()
4639
'/this/is/foobar_value/a/url',
4740
array(
4841
'token_the_first' => array(
49-
'provider' => 'foobar_provider',
42+
'name' => 'foobar_provider',
5043
'value' => 'foobar_value',
44+
'options' => array(),
5145
),
5246
),
5347
),
@@ -56,16 +50,19 @@ public function provideGenerateUrl()
5650
'/that/was/foobar_value/a/url',
5751
array(
5852
'token_the_first' => array(
59-
'provider' => 'foobar_provider',
53+
'name' => 'foobar_provider',
6054
'value' => 'foobar_value',
55+
'options' => array(),
6156
),
6257
'this' => array(
63-
'provider' => 'barfoo_provider',
58+
'name' => 'barfoo_provider',
6459
'value' => 'that',
60+
'options' => array(),
6561
),
6662
'is' => array(
67-
'provider' => 'dobar_provider',
63+
'name' => 'dobar_provider',
6864
'value' => 'was',
65+
'options' => array(),
6966
),
7067
),
7168
),
@@ -78,33 +75,35 @@ public function provideGenerateUrl()
7875
public function testGenerateUrl($urlSchema, $expectedUrl, $tokenProviderConfigs)
7976
{
8077
$document = new \stdClass;
78+
$this->urlContext->getSubjectObject()->willReturn($document);
8179
$this->driver->getRealClassName('stdClass')
8280
->willReturn('ThisIsMyStandardClass');
8381

8482
$this->metadataFactory->getMetadataForClass('ThisIsMyStandardClass')
8583
->willReturn($this->metadata);
8684

87-
$this->metadata->getTokenProviderConfigs()
85+
$this->metadata->getTokenProviders()
8886
->willReturn($tokenProviderConfigs);
8987

9088
$this->metadata->getUrlSchema()
9189
->willReturn($urlSchema);
9290

9391
foreach ($tokenProviderConfigs as $tokenName => $tokenProviderConfig) {
94-
$providerName = $tokenProviderConfig['provider'];
92+
$providerName = $tokenProviderConfig['name'];
9593

96-
$this->tokenProviders[$providerName] = $this->prophet->prophesize(
94+
$this->tokenProviders[$providerName] = $this->prophesize(
9795
'Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\TokenProviderInterface'
9896
);
9997

100-
$this->serviceRegistry->getTokenProvider($tokenProviderConfig['provider'])
98+
$this->serviceRegistry->getTokenProvider($tokenProviderConfig['name'])
10199
->willReturn($this->tokenProviders[$providerName]);
102100

103-
$this->tokenProviders[$providerName]->getValue($document, $tokenProviderConfig)
101+
$this->tokenProviders[$providerName]->provideValue($this->urlContext, $tokenProviderConfig['options'])
104102
->willReturn($tokenProviderConfig['value']);
103+
$this->tokenProviders[$providerName]->configureOptions(Argument::type('Symfony\Component\OptionsResolver\OptionsResolverInterface'))->shouldBeCalled();
105104
}
106105

107-
$res = $this->urlGenerator->generateUrl($document);
106+
$res = $this->urlGenerator->generateUrl($this->urlContext->reveal());
108107

109108
$this->assertEquals($expectedUrl, $res);
110109
}

0 commit comments

Comments
 (0)