Skip to content

Commit 4827afc

Browse files
committed
add functional test
1 parent d3a2f37 commit 4827afc

7 files changed

Lines changed: 220 additions & 0 deletions

File tree

tests/Functional/TestApplication/config/app_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ services:
55

66
Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\:
77
resource: '../'
8+
9+
maker:
10+
root_namespace: 'Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Generated'

tests/Functional/TestKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
88
use Sofascore\PurgatoryBundle\PurgatoryBundle;
99
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
10+
use Symfony\Bundle\MakerBundle\MakerBundle;
1011
use Symfony\Component\Config\Loader\LoaderInterface;
1112
use Symfony\Component\DependencyInjection\ContainerBuilder;
1213
use Symfony\Component\DependencyInjection\Definition;
@@ -63,6 +64,7 @@ public function registerBundles(): iterable
6364
yield new FrameworkBundle();
6465
yield new DoctrineBundle();
6566
yield new PurgatoryBundle();
67+
yield new MakerBundle();
6668
}
6769

6870
public function shutdown(): void
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Generated\Purgatory\RouteProvider;
4+
5+
use Sofascore\PurgatoryBundle\Listener\Enum\Action;
6+
use Sofascore\PurgatoryBundle\RouteProvider\PurgeRoute;
7+
use Sofascore\PurgatoryBundle\RouteProvider\RouteProviderInterface;
8+
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Competition\AnimalCompetition;
9+
10+
/**
11+
* @implements RouteProviderInterface<AnimalCompetition>
12+
*/
13+
final class AnimalCompetitionRouteProvider implements RouteProviderInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function provideRoutesFor(Action $action, object $entity, array $entityChangeSet): iterable
19+
{
20+
// add with your own logic if needed
21+
22+
yield new PurgeRoute(
23+
name: 'app_route', // replace it with your route
24+
params: [
25+
'param1' => $entity, // replace it with correct data for route parameters
26+
],
27+
);
28+
}
29+
30+
public function supports(Action $action, object $entity): bool
31+
{
32+
return $entity instanceof AnimalCompetition
33+
&& \in_array($action, [Action::Create, Action::Update, Action::Delete], true);
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Generated\Purgatory\RouteProvider;
4+
5+
use Sofascore\PurgatoryBundle\Listener\Enum\Action;
6+
use Sofascore\PurgatoryBundle\RouteProvider\PurgeRoute;
7+
use Sofascore\PurgatoryBundle\RouteProvider\RouteProviderInterface;
8+
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Plane;
9+
10+
/**
11+
* @implements RouteProviderInterface<Plane>
12+
*/
13+
final class PlaneRouteProvider implements RouteProviderInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function provideRoutesFor(Action $action, object $entity, array $entityChangeSet): iterable
19+
{
20+
// add with your own logic if needed
21+
22+
yield new PurgeRoute(
23+
name: 'app_route', // replace it with your route
24+
params: [
25+
'param1' => $entity, // replace it with correct data for route parameters
26+
],
27+
);
28+
}
29+
30+
public function supports(Action $action, object $entity): bool
31+
{
32+
return $entity instanceof Plane;
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Generated\Purgatory\RouteProvider;
4+
5+
use Sofascore\PurgatoryBundle\Listener\Enum\Action;
6+
use Sofascore\PurgatoryBundle\RouteProvider\PurgeRoute;
7+
use Sofascore\PurgatoryBundle\RouteProvider\RouteProviderInterface;
8+
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Ship;
9+
10+
/**
11+
* @implements RouteProviderInterface<Ship>
12+
*/
13+
final class ShipBuildRouteProvider implements RouteProviderInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function provideRoutesFor(Action $action, object $entity, array $entityChangeSet): iterable
19+
{
20+
// add with your own logic if needed
21+
22+
yield new PurgeRoute(
23+
name: 'app_route', // replace it with your route
24+
params: [
25+
'param1' => $entity, // replace it with correct data for route parameters
26+
],
27+
);
28+
}
29+
30+
public function supports(Action $action, object $entity): bool
31+
{
32+
return $entity instanceof Ship
33+
&& Action::Create === $action;
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Generated\Purgatory\RouteProvider;
4+
5+
use Sofascore\PurgatoryBundle\Listener\Enum\Action;
6+
use Sofascore\PurgatoryBundle\RouteProvider\PurgeRoute;
7+
use Sofascore\PurgatoryBundle\RouteProvider\RouteProviderInterface;
8+
use Sofascore\PurgatoryBundle\Tests\Functional\TestApplication\Entity\Vehicle;
9+
10+
/**
11+
* @implements RouteProviderInterface<Vehicle>
12+
*/
13+
final class VehicleFixRouteProvider implements RouteProviderInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function provideRoutesFor(Action $action, object $entity, array $entityChangeSet): iterable
19+
{
20+
// add with your own logic if needed
21+
22+
yield new PurgeRoute(
23+
name: 'app_route', // replace it with your route
24+
params: [
25+
'param1' => $entity, // replace it with correct data for route parameters
26+
],
27+
);
28+
}
29+
30+
public function supports(Action $action, object $entity): bool
31+
{
32+
return $entity instanceof Vehicle
33+
&& \in_array($action, [Action::Update, Action::Delete], true);
34+
}
35+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sofascore\PurgatoryBundle\Tests\Maker;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\TestWith;
9+
use Sofascore\PurgatoryBundle\Maker\MakeRouteProvider;
10+
use Sofascore\PurgatoryBundle\Tests\Functional\AbstractKernelTestCase;
11+
use Symfony\Bundle\FrameworkBundle\Console\Application;
12+
use Symfony\Component\Console\Tester\CommandTester;
13+
use Symfony\Component\Filesystem\Filesystem;
14+
15+
#[CoversClass(MakeRouteProvider::class)]
16+
final class MakeRouteProviderTest extends AbstractKernelTestCase
17+
{
18+
private string|false $colSize;
19+
private CommandTester $command;
20+
21+
protected function setUp(): void
22+
{
23+
$this->colSize = getenv('COLUMNS');
24+
putenv('COLUMNS=300');
25+
26+
self::initializeApplication(['test_case' => 'TestApplication', 'config' => 'app_config.yaml']);
27+
28+
$this->command = new CommandTester((new Application(self::$kernel))->find('make:purgatory-provider'));
29+
}
30+
31+
protected function tearDown(): void
32+
{
33+
putenv($this->colSize ? 'COLUMNS='.$this->colSize : 'COLUMNS');
34+
35+
unset(
36+
$this->colSize,
37+
$this->command,
38+
);
39+
40+
(new Filesystem())->remove(__DIR__.'/../Functional/TestApplication/Generated/');
41+
42+
parent::tearDown();
43+
}
44+
45+
#[TestWith([
46+
'input' => ['PlaneRouteProvider', 'Plane', 'no'],
47+
'expected' => 'PlaneRouteProvider',
48+
])]
49+
#[TestWith([
50+
'input' => ['Plane', 'Plane', 'no'],
51+
'expected' => 'PlaneRouteProvider',
52+
])]
53+
#[TestWith([
54+
'input' => ['ShipBuild', 'Ship', 'yes', '0'],
55+
'expected' => 'ShipBuildRouteProvider',
56+
])]
57+
#[TestWith([
58+
'input' => ['VehicleFix', 'Vehicle', 'yes', '1,2'],
59+
'expected' => 'VehicleFixRouteProvider',
60+
])]
61+
#[TestWith([
62+
'input' => ['AnimalCompetition', 'Animal', '1', 'yes', '0,1,2'],
63+
'expected' => 'AnimalCompetitionRouteProvider',
64+
])]
65+
public function testGenerateRouteProvider(array $input, string $expected): void
66+
{
67+
$this->command->setInputs([implode(\PHP_EOL, $input).\PHP_EOL]);
68+
$this->command->execute([], ['interactive' => true]);
69+
70+
self::assertFileExists(__DIR__."/../Functional/TestApplication/Generated/Purgatory/RouteProvider/$expected.php");
71+
self::assertFileEquals(
72+
expected: __DIR__."/Expected/$expected.txt",
73+
actual: __DIR__."/../Functional/TestApplication/Generated/Purgatory/RouteProvider/$expected.php",
74+
);
75+
}
76+
}

0 commit comments

Comments
 (0)