Skip to content

Commit

Permalink
Add Unit tests for Class Reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jan 10, 2022
1 parent 77bff28 commit 9b061fe
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Bundle/Routing/RoutesAttributesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
final class RoutesAttributesLoader
{
private array $mapping;

public function __construct(array $mapping)
{
$this->mapping = $mapping;
Expand Down
4 changes: 0 additions & 4 deletions src/Bundle/Tests/Routing/RoutesAttributesLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ public function it_generates_routes_from_resource_with_requirements(): void
*/
public function it_generates_routes_from_resource_with_priority(): void
{
if (\PHP_VERSION_ID < 80000 || Kernel::MAJOR_VERSION < 5) {
$this->markTestSkipped();
}

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

$container = static::$container;
Expand Down
3 changes: 2 additions & 1 deletion src/Bundle/spec/Routing/RoutesAttributesLoaderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function it_generates_routes_from_resource_with_options(): void
]);
}

function it_generates_routes_from_resource_with_host(): void {
function it_generates_routes_from_resource_with_host(): void
{
$routes = $this->__invoke();
$route = $routes->get('show_book_with_host');
$route->getPath()->shouldReturn('/book/{id}');
Expand Down
9 changes: 9 additions & 0 deletions src/Component/Tests/Dummy/DummyClassOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Sylius\Component\Resource\Tests\Dummy;

final class DummyClassOne
{
}
9 changes: 9 additions & 0 deletions src/Component/Tests/Dummy/DummyClassTwo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Sylius\Component\Resource\Tests\Dummy;

final class DummyClassTwo
{
}
9 changes: 9 additions & 0 deletions src/Component/Tests/Dummy/TraitPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Sylius\Component\Resource\Tests\Dummy;

trait TraitPass
{
}
42 changes: 42 additions & 0 deletions src/Component/Tests/Reflection/ClassReflectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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 Reflection;

use PHPUnit\Framework\TestCase;
use Sylius\Component\Resource\Reflection\ClassReflection;
use Sylius\Component\Resource\Tests\Dummy\DummyClassOne;
use Sylius\Component\Resource\Tests\Dummy\DummyClassTwo;
use Sylius\Component\Resource\Tests\Dummy\TraitPass;

final class ClassReflectionTest extends TestCase
{
/** @test */
public function it_returns_resource_classes_from_a_directory(): void
{
$resources = ClassReflection::getResourcesByPath(dirname(__FILE__).'/../Dummy');

$this->assertSame($resources, [
DummyClassOne::class,
DummyClassTwo::class,
]);
}

/** @test */
public function it_excludes_traits(): void
{
$resources = ClassReflection::getResourcesByPath(dirname(__FILE__).'/../Dummy');

$this->assertNotContains(TraitPass::class, $resources);
}
}

0 comments on commit 9b061fe

Please sign in to comment.