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

Commit 52bf8e8

Browse files
committed
Added missing unit tests, fixed AdapterInterface
1 parent 7682890 commit 52bf8e8

File tree

8 files changed

+216
-5
lines changed

8 files changed

+216
-5
lines changed

AutoRoute/Adapter/AdapterInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ public function removeAutoRoute(AutoRouteInterface $autoRoute);
119119
* object.
120120
*
121121
* @param object $contentDocument
122+
*
123+
* @return array
122124
*/
123125
public function getReferringAutoRoutes($contentDocument);
126+
127+
/**
128+
* Create a new redirect route at the path of the given
129+
* referringAutoRoute.
130+
*
131+
* The referring auto route should either be deleted or scheduled to be removed,
132+
* so the route created here will replace it.
133+
*
134+
* The new redirecvt route should redirect the request to the URL determined by
135+
* the $newRoute.
136+
*
137+
* @param AutoRouteInterface $referringAutoRoute
138+
* @param AutoRouteInterface $newRoute
139+
*/
140+
public function createRedirectRoute(AutoRouteInterface $referringAutoRoute, AutoRouteInterface $newRoute);
124141
}

AutoRoute/Adapter/PhpcrOdmAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ private function buildParentPathForUrl($url)
153153
return $document;
154154
}
155155

156-
public function createRedirectRoute($referringAutoRoute, $newRoute)
156+
/**
157+
* {@inheritDoc}
158+
*/
159+
public function createRedirectRoute(AutoRouteInterface $referringAutoRoute, AutoRouteInterface $newRoute)
157160
{
158161
$parentDocument = $referringAutoRoute->getParent();
159162

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testPersistBlog()
6363
public function provideTestUpdateBlog()
6464
{
6565
return array(
66-
// array(false),
66+
array(false),
6767
array(true),
6868
);
6969
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Unit\AutoRoute\DefunctRouteHandler;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\DefunctRouteHandler\DelegatingDefunctRouteHandler;
7+
8+
class DelegatingDefunctRouteHandlerTest extends BaseTestCase
9+
{
10+
protected $metadataFactory;
11+
protected $adapter;
12+
protected $serviceRegistry;
13+
protected $urlContextCollection;
14+
protected $metadata;
15+
16+
public function setUp()
17+
{
18+
parent::setUp();
19+
$this->metadataFactory = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Mapping\MetadataFactory');
20+
$this->adapter = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Adapter\AdapterInterface');
21+
$this->serviceRegistry = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\ServiceRegistry');
22+
$this->urlContextCollection = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContextCollection');
23+
$this->metadata = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Mapping\ClassMetadata');
24+
$this->delegatedHandler = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\DefunctRouteHandlerInterface');
25+
26+
$this->subjectObject = new \stdClass;
27+
28+
$this->delegatingDefunctRouteHandler = new DelegatingDefunctRouteHandler(
29+
$this->metadataFactory->reveal(),
30+
$this->adapter->reveal(),
31+
$this->serviceRegistry->reveal(),
32+
$this->urlContextCollection->reveal()
33+
);
34+
}
35+
36+
public function testHandleDefunctRoutes()
37+
{
38+
$this->urlContextCollection->getSubjectObject()->willReturn($this->subjectObject);
39+
$this->adapter->getRealClassName('stdClass')->willReturn('stdClass');
40+
$this->metadataFactory->getMetadataForClass('stdClass')->willReturn($this->metadata);
41+
$this->metadata->getDefunctRouteHandler()->willReturn(array(
42+
'name' => 'foobar'
43+
));
44+
$this->serviceRegistry->getDefunctRouteHandler('foobar')->willReturn($this->delegatedHandler);
45+
$this->delegatedHandler->handleDefunctRoutes($this->urlContextCollection->reveal())->shouldBeCalled();
46+
$this->delegatingDefunctRouteHandler->handleDefunctRoutes($this->urlContextCollection->reveal());
47+
}
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Unit\AutoRoute\DefunctRouteHandler;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\DefunctRouteHandler\LeaveRedirectDefunctRouteHandler;
7+
8+
class LeaveRedirectDefunctRouteHandlerTest extends BaseTestCase
9+
{
10+
protected $adapter;
11+
protected $urlContextCollection;
12+
13+
public function setUp()
14+
{
15+
parent::setUp();
16+
$this->adapter = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Adapter\AdapterInterface');
17+
$this->urlContextCollection = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContextCollection');
18+
$this->route1 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
19+
$this->route2 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
20+
$this->route3 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
21+
$this->route4 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
22+
23+
$this->subjectObject = new \stdClass;
24+
25+
$this->handler = new LeaveRedirectDefunctRouteHandler(
26+
$this->adapter->reveal()
27+
);
28+
}
29+
30+
public function testHandleDefunctRoutes()
31+
{
32+
$this->urlContextCollection->getSubjectObject()->willReturn($this->subjectObject);
33+
$this->adapter->getReferringAutoRoutes($this->subjectObject)->willReturn(array(
34+
$this->route1, $this->route2
35+
));
36+
$this->urlContextCollection->containsAutoRoute($this->route1->reveal())->willReturn(true);
37+
$this->urlContextCollection->containsAutoRoute($this->route2->reveal())->willReturn(false);
38+
$this->urlContextCollection->containsAutoRoute($this->route3->reveal())->willReturn(true);
39+
40+
$this->route2->getAutoRouteTag()->willReturn('fr');
41+
$this->urlContextCollection->getAutoRouteByTag('fr')->willReturn($this->route4);
42+
43+
$this->adapter->migrateAutoRouteChildren($this->route2->reveal(), $this->route4->reveal())->shouldBeCalled();
44+
$this->adapter->removeAutoRoute($this->route2->reveal())->shouldBeCalled();
45+
$this->adapter->createRedirectRoute($this->route2->reveal(), $this->route4->reveal())->shouldBeCalled();
46+
47+
$this->handler->handleDefunctRoutes($this->urlContextCollection->reveal());
48+
}
49+
}
50+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Unit\AutoRoute\DefunctRouteHandler;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\DefunctRouteHandler\RemoveDefunctRouteHandler;
7+
8+
class RemoveDefunctRouteHandlerTest extends BaseTestCase
9+
{
10+
protected $adapter;
11+
protected $urlContextCollection;
12+
13+
public function setUp()
14+
{
15+
parent::setUp();
16+
$this->adapter = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\Adapter\AdapterInterface');
17+
$this->urlContextCollection = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContextCollection');
18+
$this->route1 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
19+
$this->route2 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
20+
$this->route3 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
21+
$this->route4 = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
22+
23+
$this->subjectObject = new \stdClass;
24+
25+
$this->handler = new RemoveDefunctRouteHandler(
26+
$this->adapter->reveal()
27+
);
28+
}
29+
30+
public function testHandleDefunctRoutes()
31+
{
32+
$this->urlContextCollection->getSubjectObject()->willReturn($this->subjectObject);
33+
$this->adapter->getReferringAutoRoutes($this->subjectObject)->willReturn(array(
34+
$this->route1, $this->route2
35+
));
36+
$this->urlContextCollection->containsAutoRoute($this->route1->reveal())->willReturn(true);
37+
$this->urlContextCollection->containsAutoRoute($this->route2->reveal())->willReturn(false);
38+
$this->urlContextCollection->containsAutoRoute($this->route3->reveal())->willReturn(true);
39+
40+
$this->route2->getAutoRouteTag()->willReturn('fr');
41+
$this->urlContextCollection->getAutoRouteByTag('fr')->willReturn($this->route4);
42+
43+
$this->adapter->migrateAutoRouteChildren($this->route2->reveal(), $this->route4->reveal())->shouldBeCalled();
44+
$this->adapter->removeAutoRoute($this->route2->reveal())->shouldBeCalled();
45+
46+
$this->handler->handleDefunctRoutes($this->urlContextCollection->reveal());
47+
}
48+
}
49+
50+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\AutoRoute\TokenProvider;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\BaseTestCase;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\TokenProvider\ContentLocaleProvider;
7+
8+
class ContentLocaleProviderTest extends BaseTestCase
9+
{
10+
protected $slugifier;
11+
protected $article;
12+
protected $urlContext;
13+
14+
public function setUp()
15+
{
16+
parent::setUp();
17+
18+
$this->urlContext = $this->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\AutoRoute\UrlContext');
19+
$this->provider = new ContentLocaleProvider($this->slugifier->reveal());
20+
}
21+
22+
public function testGetValue()
23+
{
24+
$this->urlContext->getLocale()->willReturn('de');
25+
$res = $this->provider->provideValue($this->urlContext->reveal(), array());
26+
$this->assertEquals('de', $res);
27+
}
28+
}
29+

Tests/Unit/BaseTestCase.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,27 @@ public function setUp()
1313
$this->prophet = new Prophet();
1414
}
1515

16-
public function tearDown()
16+
public function prophesize($classOrInterface = null)
17+
{
18+
return $this->prophet->prophesize($classOrInterface);
19+
}
20+
21+
protected function assertPostConditions()
1722
{
1823
$this->prophet->checkPredictions();
1924
}
2025

21-
public function prophesize($classOrInterface = null)
26+
protected function tearDown()
2227
{
23-
return $this->prophet->prophesize($classOrInterface);
28+
$this->prophet = null;
29+
}
30+
31+
protected function onNotSuccessfulTest(\Exception $e)
32+
{
33+
if ($e instanceof PredictionException) {
34+
$e = new \PHPUnit_Framework_AssertionFailedError($e->getMessage(), $e->getCode(), $e);
35+
}
36+
37+
return parent::onNotSuccessfulTest($e);
2438
}
2539
}

0 commit comments

Comments
 (0)