Skip to content

Commit

Permalink
Add Single route with template and with repository
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 10, 2022
1 parent 500410d commit 35dbac9
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Bundle/Routing/AttributesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ private function addRoutesForSyliusRouteAttributes(RouteCollection $routeCollect
$syliusOptions['criteria'] = $arguments['criteria'];
}

if (isset($arguments['repository'])) {
$syliusOptions['repository'] = $arguments['repository'];
}

$route = new Route(
$arguments['path'],
[
Expand Down
59 changes: 59 additions & 0 deletions src/Bundle/Tests/Routing/AttributesLoaderForSyliusRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,63 @@ public function it_generates_route_from_resource_with_criteria(): void
],
], $route->getDefaults());
}

/**
* @test
*/
public function it_generates_route_from_resource_with_template(): void
{
if (\PHP_VERSION_ID < 80000) {
$this->markTestSkipped();
}

self::bootKernel(['environment' => 'test_with_attributes']);

$container = static::$container;

$attributesLoader = $container->get('sylius.routing.loader.attributes');

$routesCollection = $attributesLoader->__invoke();

$route = $routesCollection->get('show_book_with_template');
$this->assertNotNull($route);
$this->assertEquals('/book/{id}', $route->getPath());
$this->assertEquals([
'_controller' => 'app.controller.book:showAction',
'_sylius' => [
'template' => 'book/show.html.twig',
],
], $route->getDefaults());
}

/**
* @test
*/
public function it_generates_route_from_resource_with_repository(): void
{
if (\PHP_VERSION_ID < 80000) {
$this->markTestSkipped();
}

self::bootKernel(['environment' => 'test_with_attributes']);

$container = static::$container;

$attributesLoader = $container->get('sylius.routing.loader.attributes');

$routesCollection = $attributesLoader->__invoke();

$route = $routesCollection->get('show_book_with_repository');
$this->assertNotNull($route);
$this->assertEquals('/book/{id}', $route->getPath());
$this->assertEquals([
'_controller' => 'app.controller.book:showAction',
'_sylius' => [
'repository' => [
'method' => 'findOneNewestByAuthor',
'arguments' => '[$author]',
],
],
], $route->getDefaults());
}
}
35 changes: 35 additions & 0 deletions src/Bundle/test/src/Entity/Route/ShowBookWithRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity\Route;

use App\Entity\Book;
use JMS\Serializer\Annotation as Serializer;
use RectorPrefix20210817\template;
use Sylius\Component\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[SyliusRoute(
name: 'show_book_with_repository',
path: '/book/{id}',
controller: 'app.controller.book:showAction',
repository: [
'method' => 'findOneNewestByAuthor',
'arguments' => '[$author]',
]
)]
class ShowBookWithRepository extends Book
{
}
32 changes: 32 additions & 0 deletions src/Bundle/test/src/Entity/Route/ShowBookWithTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity\Route;

use App\Entity\Book;
use JMS\Serializer\Annotation as Serializer;
use RectorPrefix20210817\template;
use Sylius\Component\Resource\Annotation\SyliusRoute;

/**
* @Serializer\ExclusionPolicy("all")
*/
#[SyliusRoute(
name: 'show_book_with_template',
path: '/book/{id}',
controller: 'app.controller.book:showAction',
template: 'book/show.html.twig'
)]
class ShowBookWithTemplate extends Book
{
}

0 comments on commit 35dbac9

Please sign in to comment.