Skip to content

Commit 4169a53

Browse files
acrobatdbu
authored andcommitted
Added extra tests for new and deprecated behaviour
1 parent bdd0299 commit 4169a53

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/Unit/Routing/ChainRouterTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Psr\Log\LoggerInterface;
1717
use Symfony\Cmf\Component\Routing\ChainRouter;
18+
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
1819
use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
@@ -717,6 +718,54 @@ public function testGenerateObjectName()
717718
$this->assertEquals($name, $result);
718719
}
719720

721+
public function testGenerateWithObjectNameInParametersNotFoundVersatile()
722+
{
723+
$name = RouteObjectInterface::OBJECT_BASED_ROUTE_NAME;
724+
$parameters = ['test' => 'value', '_route_object' => new \stdClass()];
725+
726+
$chainedRouter = $this->createMock(VersatileRouter::class);
727+
$chainedRouter
728+
->expects($this->once())
729+
->method('supports')
730+
->willReturn(true)
731+
;
732+
$chainedRouter->expects($this->once())
733+
->method('generate')
734+
->with($name, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH)
735+
->will($this->throwException(new RouteNotFoundException()))
736+
;
737+
$chainedRouter->expects($this->once())
738+
->method('getRouteDebugMessage')
739+
->with($name, $parameters)
740+
->willReturn('message')
741+
;
742+
743+
$this->router->add($chainedRouter, 10);
744+
745+
$this->expectException(RouteNotFoundException::class);
746+
$this->router->generate($name, $parameters);
747+
}
748+
749+
public function testGenerateWithObjectNameInParameters()
750+
{
751+
$name = RouteObjectInterface::OBJECT_BASED_ROUTE_NAME;
752+
$parameters = ['test' => 'value', '_route_object' => new \stdClass()];
753+
754+
$defaultRouter = $this->createMock(RouterInterface::class);
755+
756+
$defaultRouter
757+
->expects($this->once())
758+
->method('generate')
759+
->with($name, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH)
760+
->willReturn($name)
761+
;
762+
763+
$this->router->add($defaultRouter, 200);
764+
765+
$result = $this->router->generate($name, $parameters);
766+
$this->assertEquals($name, $result);
767+
}
768+
720769
public function testWarmup()
721770
{
722771
$dir = 'test_dir';

tests/Unit/Routing/ContentAwareGeneratorTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Cmf\Component\Routing\ContentAwareGenerator;
1717
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;
18+
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
1819
use Symfony\Cmf\Component\Routing\RouteProviderInterface;
1920
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
2021
use Symfony\Cmf\Component\Routing\Tests\Unit\Routing\RouteMock;
@@ -87,6 +88,19 @@ public function testGenerateFromContent()
8788
$this->assertEquals('result_url', $this->generator->generate($this->contentDocument));
8889
}
8990

91+
public function testGenerateFromContentInParameters()
92+
{
93+
$this->provider->expects($this->never())
94+
->method('getRouteByName')
95+
;
96+
$this->routeDocument->expects($this->once())
97+
->method('compile')
98+
->willReturn($this->routeCompiled)
99+
;
100+
101+
$this->assertEquals('result_url', $this->generator->generate(RouteObjectInterface::OBJECT_BASED_ROUTE_NAME, [RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument]));
102+
}
103+
90104
public function testGenerateFromContentId()
91105
{
92106
$this->provider->expects($this->never())

0 commit comments

Comments
 (0)