diff --git a/composer.json b/composer.json index 07bbcd1..6e7d7eb 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^5.6|^7.0", "symfony/framework-bundle": "^2.8|^3.0", - "symfony-cmf/routing-auto": "2.0.0-RC2", + "symfony-cmf/routing-auto": "^2.0.0-RC5", "symfony-cmf/routing-bundle": "^1.2.0|^2.0", "aferrandini/urlizer": "1.0.*", "phpdocumentor/reflection-docblock": "^3.1, !=3.2.0" diff --git a/src/Adapter/PhpcrOdmAdapter.php b/src/Adapter/PhpcrOdmAdapter.php index d1fc707..ce0495d 100644 --- a/src/Adapter/PhpcrOdmAdapter.php +++ b/src/Adapter/PhpcrOdmAdapter.php @@ -111,9 +111,10 @@ public function removeAutoRoute(AutoRouteInterface $autoRoute) /** * {@inheritdoc} */ - public function createAutoRoute(UriContext $uriContext, $contentDocument, $locale) + public function createAutoRoute(UriContext $uriContext, $locale) { $basePath = $this->baseRoutePath; + $contentDocument = $uriContext->getSubject(); $document = $parentDocument = $this->dm->find(null, $basePath); if (null === $parentDocument) { diff --git a/tests/Unit/Adapter/PhpcrOdmAdapterTest.php b/tests/Unit/Adapter/PhpcrOdmAdapterTest.php index ce0a43b..c4b5d52 100644 --- a/tests/Unit/Adapter/PhpcrOdmAdapterTest.php +++ b/tests/Unit/Adapter/PhpcrOdmAdapterTest.php @@ -11,12 +11,63 @@ namespace Symfony\Cmf\Component\RoutingAuto\Tests\Unit\Adapter; +use Doctrine\ODM\PHPCR\DocumentManager; +use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; +use PHPCR\NodeInterface; +use PHPCR\SessionInterface; +use Prophecy\Prophecy\ObjectProphecy; use Symfony\Cmf\Bundle\RoutingAutoBundle\Adapter\PhpcrOdmAdapter; +use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface; +use Symfony\Cmf\Component\RoutingAuto\UriContext; +use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; class PhpcrOdmAdapterTest extends \PHPUnit_Framework_TestCase { - protected $dm; - protected $baseRoutePath; + /** + * @var DocumentManager|ObjectProphecy + */ + private $dm; + + /** + * @var ClassMetadataFactory|ObjectProphecy + */ + private $metadataFactory; + + /** + * @var ClassMetadata|ObjectProphecy + */ + private $metadata; + + private $contentDocument; + private $contentDocument2; + private $baseNode; + private $parentRoute; + + /** + * @var AutoRouteInterface|ObjectProphecy + */ + private $route; + + /** + * @var UriContext|ObjectProphecy + */ + private $uriContext; + + /** + * @var SessionInterface|ObjectProphecy + */ + private $phpcrSession; + + /** + * @var NodeInterface|ObjectProphecy + */ + private $phpcrRootNode; + private $baseRoutePath; + + /** + * @var PhpcrOdmAdapter + */ + private $adapter; public function setUp() { @@ -118,7 +169,8 @@ public function testCreateAutoRoute($path, $expectedParentPath, $expectedName, $ $this->uriContext->getUri()->willReturn($path); $this->uriContext->getDefaults()->willReturn([]); - $res = $this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'fr'); + $this->uriContext->getSubject()->willReturn($this->contentDocument); + $res = $this->adapter->createAutoRoute($this->uriContext->reveal(), 'fr'); $this->assertNotNull($res); $this->assertInstanceOf('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute', $res); $this->assertEquals($expectedName, $res->getName()); @@ -146,8 +198,9 @@ public function testCreateAutoRouteSetDefaults() 'one' => 'k1', 'two' => 'k2', ]); + $this->uriContext->getSubject()->willReturn($this->contentDocument); - $res = $this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'fr'); + $res = $this->adapter->createAutoRoute($this->uriContext->reveal(), 'fr'); $this->assertNotNull($res); $this->assertInstanceOf('Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute', $res); $this->assertEquals('to', $res->getName()); @@ -184,7 +237,8 @@ public function testCreateAutoRouteThrowsExceptionIfItCannotMigrateExistingGener new \stdClass() ); $this->uriContext->getUri()->willReturn($uri); - $this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'it'); + $this->uriContext->getSubject()->willReturn($this->contentDocument); + $this->adapter->createAutoRoute($this->uriContext->reveal(), 'it'); } /** @@ -196,7 +250,8 @@ public function testCreateAutoRouteNonExistingBasePath() $this->dm->getPhpcrSession()->willReturn($this->phpcrSession); $this->dm->find(null, $this->baseRoutePath)->willReturn(null); $this->uriContext->getUri()->willReturn('/asdasd'); - $this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'fr'); + $this->uriContext->getSubject()->willReturn($this->contentDocument); + $this->adapter->createAutoRoute($this->uriContext->reveal(), 'fr'); } public function testGetRealClassName()