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

Commit d3ad7fc

Browse files
committed
Fixed OdmAdapter unit tests
1 parent 2cef3cd commit d3ad7fc

File tree

5 files changed

+25
-108
lines changed

5 files changed

+25
-108
lines changed

Doctrine/Phpcr/AutoRouteListener.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
class AutoRouteListener
2828
{
29+
protected $inFlush = false;
30+
protected $postFlushDone = false;
31+
2932
public function __construct(ContainerInterface $container)
3033
{
3134
$this->container = $container;
@@ -48,6 +51,10 @@ protected function getMetadataFactory()
4851

4952
public function onFlush(ManagerEventArgs $args)
5053
{
54+
if ($this->inFlush) {
55+
return;
56+
}
57+
5158
/** @var $dm DocumentManager */
5259
$dm = $args->getObjectManager();
5360
$uow = $dm->getUnitOfWork();
@@ -91,11 +98,18 @@ public function onFlush(ManagerEventArgs $args)
9198
}
9299
}
93100

94-
public function postFlush(ManagerEventArgs $args)
101+
public function endFlush(ManagerEventArgs $args)
95102
{
96103
$dm = $args->getObjectManager();
97104
$arm = $this->getAutoRouteManager();
98105
$arm->handleDefunctRoutes();
106+
107+
if (!$this->postFlushDone) {
108+
$this->postFlushDone = true;
109+
$dm->flush();
110+
}
111+
112+
$this->postFlushDone = false;
99113
}
100114

101115
private function isAutoRouteable($document)

Resources/config/auto_route.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<service id="cmf_routing_auto.phpcrodm_auto_route_listener" class="%cmf_routing_auto.phpcrodm_auto_route_listener.class%">
6060
<argument type="service" id="service_container"/>
6161
<tag name="doctrine_phpcr.event_listener" event="onFlush"/>
62-
<tag name="doctrine_phpcr.event_listener" event="postFlush"/>
62+
<tag name="doctrine_phpcr.event_listener" event="endFlush"/>
6363
</service>
6464

6565
<!-- Metadata -->

Tests/Spec/Symfony/Cmf/Bundle/RoutingAutoBundle/AutoRoute/DefunctRouteHandler/LeaveRedirectDefunctRouteHandlerSpec.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

Tests/Spec/Symfony/Cmf/Bundle/RoutingAutoBundle/AutoRoute/UrlContextCollectionSpec.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

Tests/Unit/AutoRoute/Adapter/PhpcrOdmAdapterTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class PhpcrOdmAdapterTest extends BaseTestCase
99
{
1010
protected $dm;
11+
protected $baseRoutePath;
1112

1213
public function setUp()
1314
{
@@ -18,8 +19,9 @@ public function setUp()
1819
$this->metadata = $this->prophet->prophesize('Doctrine\ODM\PHPCR\Mapping\ClassMetadata');
1920
$this->contentDocument = new \stdClass;
2021
$this->contentDocument2 = new \stdClass;
22+
$this->baseNode = new \stdClass;
2123
$this->parentRoute = new \stdClass;
22-
$this->route = $this->prophet->prophesize('Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route');
24+
$this->route = $this->prophet->prophesize('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface');
2325

2426
$this->phpcrSession = $this->prophet->prophesize('PHPCR\SessionInterface');
2527
$this->phpcrRootNode = $this->prophet->prophesize('PHPCR\NodeInterface');
@@ -84,17 +86,19 @@ public function testTranslateObject($className, $id, $locale)
8486
public function provideCreateRoute()
8587
{
8688
return array(
87-
array('/foo/bar', '/foo', 'bar', true)
89+
array('/foo/bar', '/test/foo', 'bar', true)
8890
);
8991
}
9092

9193
/**
9294
* @dataProvider provideCreateRoute
9395
*/
94-
public function testCreateRoute($path, $expectedParentPath, $expectedName, $parentPathExists)
96+
public function testCreateAutoRoute($path, $expectedParentPath, $expectedName, $parentPathExists)
9597
{
9698
$this->dm->getPhpcrSession()->willReturn($this->phpcrSession);
9799
$this->phpcrSession->getRootNode()->willReturn($this->phpcrRootNode);
100+
$this->dm->find(null, $this->baseRoutePath)->willReturn($this->baseNode);
101+
98102
if ($parentPathExists) {
99103
$this->dm->find(null, $expectedParentPath)
100104
->willReturn($this->parentRoute);
@@ -107,6 +111,7 @@ public function testCreateRoute($path, $expectedParentPath, $expectedName, $pare
107111
$this->assertNotNull($res);
108112
$this->assertInstanceOf('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute', $res);
109113
$this->assertEquals($expectedName, $res->getName());
114+
110115
$this->assertSame($this->parentRoute, $res->getParent());
111116
$this->assertSame($this->contentDocument, $res->getContent());
112117
}
@@ -138,7 +143,7 @@ public function testCompareRouteContent($isMatch)
138143

139144
public function testGetReferringRoutes()
140145
{
141-
$this->dm->getReferrers($this->contentDocument, null, null, null, 'Symfony\Cmf\Component\Routing\RouteObjectInterface')
146+
$this->dm->getReferrers($this->contentDocument, null, null, null, 'Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRouteInterface')
142147
->willReturn(array($this->route));
143148
$res = $this->adapter->getReferringAutoRoutes($this->contentDocument);
144149

0 commit comments

Comments
 (0)