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

Commit 579a31e

Browse files
committed
Fixed tests
1 parent 4323bfc commit 579a31e

File tree

6 files changed

+92
-12
lines changed

6 files changed

+92
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
/Tests/Functional/app/cache/

Resources/config/auto_route.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parameters>
77
<parameter key="symfony_cmf_routing_auto_route.phpcrodm_auto_route_subscriber_class">Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Subscriber\AutoRouteSubscriber</parameter>
88
<parameter key="symfony_cmf_routing_auto_route.auto_route_manager_class">Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager</parameter>
9-
<parameter key="symfony_cmf_routing_auto_route.basepath"></parameter>
9+
<parameter key="symfony_cmf_routing_auto_route.base_path"></parameter>
1010
<parameter key="symfony_cmf_routing_auto_route.auto_route_by_class"></parameter>
1111
</parameters>
1212

@@ -25,7 +25,7 @@
2525
<argument type="service" id="doctrine_phpcr.odm.default_document_manager"/>
2626
<argument>%symfony_cmf_routing_auto_route.auto_route_by_class%</argument>
2727
<argument type="service" id="symfony_cmf_routing_auto_route.slugifier"/>
28-
<argument>%symfony_cmf_routing_auto_route.basepath%</argument>
28+
<argument>%symfony_cmf_routing_auto_route.base_path%</argument>
2929
</service>
3030

3131
<service id="symfony_cmf_routing_auto_route.phpcrodm_auto_route_subscriber" class="%symfony_cmf_routing_auto_route.phpcrodm_auto_route_subscriber_class%">
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/phpcr/doctrine-mapping"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
4+
<document
5+
name="Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Document\AutoRoute"
6+
referenceable="true"/>
7+
8+
</doctrine-mapping>
9+

Subscriber/AutoRouteSubscriber.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Subscriber;
4+
5+
use Doctrine\Common\EventSubscriber;
6+
use Doctrine\ODM\PHPCR\Event;
7+
use Symfony\Cmf\Bundle\RoutingAutoRouteBundle\AutoRoute\AutoRouteManager;
8+
use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs;
9+
use Doctrine\ODM\PHPCR\Event\PostFlushEventArgs;
10+
use Doctrine\ODM\PHPCR\Event\OnFlushEventArgs;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
12+
13+
/**
14+
* Doctrine PHPCR ODM Subscriber for maintaining automatic routes.
15+
*
16+
* @author Daniel Leech <[email protected]>
17+
*/
18+
class AutoRouteSubscriber implements EventSubscriber
19+
{
20+
protected $persistQueue = array();
21+
protected $removeQueue = array();
22+
23+
public function __construct(ContainerInterface $container)
24+
{
25+
$this->container = $container;
26+
}
27+
28+
public function getSubscribedEvents()
29+
{
30+
return array(
31+
Event::onFlush,
32+
);
33+
}
34+
35+
protected function getArm()
36+
{
37+
return $this->container->get('symfony_cmf_routing_auto_route.auto_route_manager');
38+
}
39+
40+
public function onFlush(OnFlushEventArgs $args)
41+
{
42+
$dm = $args->getDocumentManager();
43+
$uow = $dm->getUnitOfWork();
44+
45+
$scheduledInserts = $uow->getScheduledInserts();
46+
$scheduledUpdates = $uow->getScheduledUpdates();
47+
$updates = array_merge($scheduledInserts, $scheduledUpdates);
48+
49+
foreach ($updates as $document) {
50+
if ($this->getArm()->isAutoRouteable($document)) {
51+
$route = $this->getArm()->updateAutoRouteForDocument($document);
52+
$uow->computeSingleDocumentChangeSet($route);
53+
}
54+
}
55+
56+
$removes = $uow->getScheduledRemovals();
57+
58+
foreach ($removes as $document) {
59+
if ($this->getArm()->isAutoRouteable($document)) {
60+
$routes = $this->getArm()->fetchAutoRoutesForDocument($document);
61+
foreach ($routes as $route) {
62+
$uow->scheduleRemove($route);
63+
}
64+
}
65+
}
66+
}
67+
}
68+

Tests/AutoRoute/AutoRouteManagerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ class AutoRouteManagerTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public function setUp()
1212
{
13+
$this->phpcrSession = $this->getMock('PHPCR\SessionInterface');
1314
$this->dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
1415
->disableOriginalConstructor()
1516
->getMock();
17+
$this->dm->expects($this->once())
18+
->method('getPhpcrSession')
19+
->will($this->returnValue($this->phpcrSession));
20+
1621
$this->slugifier = $this->getMock('Symfony\Cmf\Bundle\CoreBundle\Slugifier\SlugifierInterface');
1722
$this->mapping = array(
1823
'Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\AutoRoute\TestDocument' => array(
1924
'base_path' => null,
20-
'route_method_name' => 'getRouteName'
25+
'route_method_name' => 'getRouteName',
26+
'base_path_auto_create' => false
2127
)
2228
);
2329

@@ -27,7 +33,6 @@ public function setUp()
2733
$this->odmMetadata = new ClassMetadata(
2834
'Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\Routing\TestDocument'
2935
);
30-
$this->phpcrSession = $this->getMock('PHPCR\SessionInterface');
3136

3237
$this->autoRouteManager = new AutoRouteManager(
3338
$this->dm,
@@ -50,11 +55,6 @@ protected function bootstrapRouteMetadata()
5055

5156
protected function bootstrapExistingDocument($isExisting)
5257
{
53-
// isExistingDocument ...
54-
$this->dm->expects($this->once())
55-
->method('getPhpcrSession')
56-
->will($this->returnValue($this->phpcrSession));
57-
5858
$this->phpcrSession->expects($this->once())
5959
->method('nodeExists')
6060
->will($this->returnValue($isExisting));

Tests/Functional/AutoRoute/AutoRouteManagerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ public function testContainer()
3030
$res = $prop->getValue($this->arm);
3131

3232
$this->assertEquals(array(
33-
'Symfony\Cmf\Bundle\AutoRouteBundle\Tests\Functional\app\Document\Post' => array(
34-
'base_path' => '/test/posts/test-post',
35-
'route_method_name' => 'getTitle'
33+
'Symfony\Cmf\Bundle\RoutingAutoRouteBundle\Tests\Functional\app\Document\Post' => array(
34+
'base_path' => '/test/auto-route/posts',
35+
'route_method_name' => 'getTitle',
36+
'base_path_auto_create' => true
3637
)
3738
), $res);
3839
}

0 commit comments

Comments
 (0)