Skip to content

Commit

Permalink
Add some other missing features for single routes
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 10, 2022
1 parent fb80bcf commit 23e4eae
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Bundle/Tests/Routing/AttributesLoaderForSyliusRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Routing;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Routing\RouteCompiler;

final class AttributesLoaderForSyliusRouteTest extends KernelTestCase
{
Expand Down Expand Up @@ -282,4 +283,78 @@ public function it_generates_route_from_resource_with_priority(): void
$this->assertNotNull($route);
$this->assertSame($route, array_values($routesCollection->all())[0]);
}

/**
* @test
*/
public function it_generates_route_from_resource_with_options(): 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_options');
$this->assertNotNull($route);
$this->assertEquals('/book/{id}', $route->getPath());
$this->assertEquals([
'compiler_class' => RouteCompiler::class,
'utf8' => true,
], $route->getOptions());
}

/**
* @test
*/
public function it_generates_route_from_resource_with_host(): 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_host');
$this->assertNotNull($route);
$this->assertEquals('/book/{id}', $route->getPath());
$this->assertEquals('m.example.com', $route->getHost());
}

/**
* @test
*/
public function it_generates_route_from_resource_with_schemes(): 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_schemes');
$this->assertNotNull($route);
$this->assertEquals('/book/{id}', $route->getPath());
$this->assertEquals([
'https',
], $route->getSchemes());
}
}
32 changes: 32 additions & 0 deletions src/Bundle/test/src/Entity/Route/ShowBookWithHost.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_host',
path: '/book/{id}',
controller: 'app.controller.book:showAction',
host: 'm.example.com'
)]
class ShowBookWithHost extends Book
{
}
32 changes: 32 additions & 0 deletions src/Bundle/test/src/Entity/Route/ShowBookWithOptions.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_options',
path: '/book/{id}',
controller: 'app.controller.book:showAction',
options: ['utf8' => true]
)]
class ShowBookWithOptions extends Book
{
}
32 changes: 32 additions & 0 deletions src/Bundle/test/src/Entity/Route/ShowBookWithSchemes.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_schemes',
path: '/book/{id}',
controller: 'app.controller.book:showAction',
schemes: ['https']
)]
class ShowBookWithSchemes extends Book
{
}

0 comments on commit 23e4eae

Please sign in to comment.