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

Commit 71ca30c

Browse files
committed
Merge pull request #155 from symfony-cmf/updated_adapter
Updated adapter
2 parents db5c654 + 4ae39e5 commit 71ca30c

File tree

4 files changed

+19
-67
lines changed

4 files changed

+19
-67
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function removeAutoRoute(AutoRouteInterface $autoRoute)
114114
/**
115115
* {@inheritDoc}
116116
*/
117-
public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
117+
public function createAutoRoute(UriContext $uriContext, $contentDocument, $autoRouteTag)
118118
{
119119
$path = $this->baseRoutePath;
120120
$document = $parentDocument = $this->dm->find(null, $path);
@@ -124,7 +124,7 @@ public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
124124
));
125125
}
126126

127-
$segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY);
127+
$segments = preg_split('#/#', $uriContext->getUri(), null, PREG_SPLIT_NO_EMPTY);
128128
$headName = array_pop($segments);
129129
foreach ($segments as $segment) {
130130
$path .= '/' . $segment;
@@ -189,7 +189,7 @@ public function getReferringAutoRoutes($contentDocument)
189189
/**
190190
* {@inheritDoc}
191191
*/
192-
public function findRouteForUri($uri)
192+
public function findRouteForUri($uri, UriContext $uriContext)
193193
{
194194
$path = $this->getPathFromUri($uri);
195195

Tests/Unit/Adapter/PhpcrOdmAdapterTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,27 @@
1212

1313
namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit\Adapter;
1414

15-
use Symfony\Cmf\Component\RoutingAuto\Tests\Unit\BaseTestCase;
1615
use Symfony\Cmf\Bundle\RoutingAutoBundle\Adapter\PhpcrOdmAdapter;
1716

18-
class PhpcrOdmAdapterTest extends BaseTestCase
17+
class PhpcrOdmAdapterTest extends \PHPUnit_Framework_TestCase
1918
{
2019
protected $dm;
2120
protected $baseRoutePath;
2221

2322
public function setUp()
2423
{
25-
parent::setUp();
26-
27-
$this->dm = $this->prophet->prophesize('Doctrine\ODM\PHPCR\DocumentManager');
28-
$this->metadataFactory = $this->prophet->prophesize('Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory');
29-
$this->metadata = $this->prophet->prophesize('Doctrine\ODM\PHPCR\Mapping\ClassMetadata');
24+
$this->dm = $this->prophesize('Doctrine\ODM\PHPCR\DocumentManager');
25+
$this->metadataFactory = $this->prophesize('Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory');
26+
$this->metadata = $this->prophesize('Doctrine\ODM\PHPCR\Mapping\ClassMetadata');
3027
$this->contentDocument = new \stdClass;
3128
$this->contentDocument2 = new \stdClass;
3229
$this->baseNode = new \stdClass;
3330
$this->parentRoute = new \stdClass;
34-
$this->route = $this->prophet->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
31+
$this->route = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface');
32+
$this->uriContext = $this->prophesize('Symfony\Cmf\Component\RoutingAuto\UriContext');
3533

36-
$this->phpcrSession = $this->prophet->prophesize('PHPCR\SessionInterface');
37-
$this->phpcrRootNode = $this->prophet->prophesize('PHPCR\NodeInterface');
34+
$this->phpcrSession = $this->prophesize('PHPCR\SessionInterface');
35+
$this->phpcrRootNode = $this->prophesize('PHPCR\NodeInterface');
3836
$this->baseRoutePath = '/test';
3937

4038
$this->adapter = new PhpcrOdmAdapter($this->dm->reveal(), $this->baseRoutePath);
@@ -117,7 +115,9 @@ public function testCreateAutoRoute($path, $expectedParentPath, $expectedName, $
117115
->willReturn(null);
118116
}
119117

120-
$res = $this->adapter->createAutoRoute($path, $this->contentDocument, 'fr');
118+
$this->uriContext->getUri()->willReturn($path);
119+
120+
$res = $this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'fr');
121121
$this->assertNotNull($res);
122122
$this->assertInstanceOf('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute', $res);
123123
$this->assertEquals($expectedName, $res->getName());
@@ -134,7 +134,8 @@ public function testCreateAutoRouteNonExistingBasePath()
134134
{
135135
$this->dm->getPhpcrSession()->willReturn($this->phpcrSession);
136136
$this->dm->find(null, $this->baseRoutePath)->willReturn(null);
137-
$this->adapter->createAutoRoute('/foo', $this->contentDocument, 'fr');
137+
$this->uriContext->getUri()->willReturn('/asdasd');
138+
$this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'fr');
138139
}
139140

140141

@@ -179,7 +180,7 @@ public function testFindRouteForUri()
179180

180181
$this->dm->find(null, $this->baseRoutePath . $uri)->willReturn($expectedRoutes);
181182

182-
$res = $this->adapter->findRouteForUri($uri);
183+
$res = $this->adapter->findRouteForUri($uri, $this->uriContext->reveal());
183184
$this->assertSame($expectedRoutes, $res);
184185
}
185186
}

Tests/Unit/BaseTestCase.php

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

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
"require-dev": {
2222
"symfony-cmf/testing": "~1.1",
2323
"symfony/yaml": "~2.1",
24-
"phpspec/prophecy": "~1.1.2",
2524
"matthiasnoback/symfony-dependency-injection-test": "0.*",
2625
"matthiasnoback/symfony-config-test": "0.*",
27-
"doctrine/phpcr-odm": "~1.2"
26+
"doctrine/phpcr-odm": "~1.2",
27+
"phpunit/phpunit": "~4.5"
2828
},
2929
"suggest": {
3030
"doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents",

0 commit comments

Comments
 (0)