Skip to content

Commit b714654

Browse files
committed
Improve UTs/FTs
1 parent 31f08ed commit b714654

15 files changed

+85
-114
lines changed

features/bundle.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: demo symfony application
22

33
Scenario: Check that all methods are available
4-
# Ensure methods with tag have been succesfully loaded
4+
# Ensure methods with tag have been successfully loaded
55
When I send a "GET" request on "/my-custom-doc-endpoint" demoApp kernel endpoint
66
Then I should have a "200" response from demoApp with following content:
77
"""

features/demo_app/src/AbstractKernel.php

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
namespace DemoApp;
33

44
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
5+
use Symfony\Component\Config\Loader\LoaderInterface;
56
use Symfony\Component\DependencyInjection\Container;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
68
use Symfony\Component\HttpKernel\Kernel as BaseHttpKernel;
9+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
10+
use Symfony\Component\Routing\RouteCollectionBuilder;
711

812
abstract class AbstractKernel extends BaseHttpKernel
913
{
@@ -13,14 +17,25 @@ abstract class AbstractKernel extends BaseHttpKernel
1317
/** @var string|null */
1418
private $customCacheDir = null;
1519

20+
public function registerBundles(): iterable
21+
{
22+
/** @noinspection PhpIncludeInspection */
23+
$contents = require $this->getConfigDir().'/bundles.php';
24+
foreach ($contents as $class => $envs) {
25+
if (isset($envs['all']) || isset($envs[$this->environment])) {
26+
yield new $class();
27+
}
28+
}
29+
}
30+
1631
/**
1732
* {@inheritdoc}
1833
*/
19-
public function getCacheDir()
34+
public function getCacheDir(): string
2035
{
2136
// Use a specific cache for each kernels
2237
if (null === $this->customCacheDir) {
23-
$this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectory();
38+
$this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectoryName();
2439
}
2540

2641
return $this->customCacheDir;
@@ -29,29 +44,58 @@ public function getCacheDir()
2944
/**
3045
* {@inheritdoc}
3146
*/
32-
public function getLogDir()
47+
public function getLogDir(): string
3348
{
3449
return $this->getProjectDir().'/var/log';
3550
}
3651

3752
/**
3853
* {@inheritdoc}
3954
*/
40-
public function getProjectDir()
55+
public function getProjectDir(): string
4156
{
4257
return realpath(__DIR__.'/../');
4358
}
4459

60+
public function getConfigDir(): string
61+
{
62+
return $this->getProjectDir().'/'.$this->getConfigDirectoryName();
63+
}
64+
65+
/**
66+
* @param RouteCollectionBuilder|RoutingConfigurator $routes
67+
*/
68+
protected function configureRoutes($routes)
69+
{
70+
$confDir = $this->getConfigDir();
71+
if ($routes instanceof RoutingConfigurator) {
72+
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, 'glob');
73+
} else {
74+
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
75+
}
76+
}
77+
78+
/**
79+
* {@inheritdoc}
80+
*/
81+
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
82+
{
83+
$container->setParameter('container.dumper.inline_class_loader', true);
84+
$confDir = $this->getConfigDir();
85+
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
86+
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
87+
}
88+
4589
/**
4690
* Gets the container class.
4791
*
4892
* @return string The container class
4993
*/
50-
protected function getContainerClass()
94+
protected function getContainerClass(): string
5195
{
5296
// In order to avoid collisions between kernels use a dedicated name
53-
return parent::getContainerClass().Container::camelize($this->getConfigDirectory());
97+
return parent::getContainerClass().Container::camelize($this->getConfigDirectoryName());
5498
}
5599

56-
abstract public function getConfigDirectory() : string;
100+
abstract public function getConfigDirectoryName() : string;
57101
}

features/demo_app/src/DefaultKernel.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
11
<?php
22
namespace DemoApp;
33

4-
use Symfony\Component\Config\Loader\LoaderInterface;
5-
use Symfony\Component\DependencyInjection\ContainerBuilder;
64
use Symfony\Component\Routing\RouteCollectionBuilder;
75

86
class DefaultKernel extends AbstractKernel
97
{
10-
public function registerBundles(): iterable
11-
{
12-
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
13-
foreach ($contents as $class => $envs) {
14-
if (isset($envs['all']) || isset($envs[$this->environment])) {
15-
yield new $class();
16-
}
17-
}
18-
}
19-
20-
/**
21-
* {@inheritdoc}
22-
*/
23-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
24-
{
25-
$container->setParameter('container.dumper.inline_class_loader', true);
26-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
27-
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
28-
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
29-
}
30-
31-
/**
32-
* {@inheritdoc}
33-
*/
34-
protected function configureRoutes(RouteCollectionBuilder $routes)
35-
{
36-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
37-
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
38-
}
39-
40-
/**
41-
* {@inheritdoc}
42-
*/
43-
public function getConfigDirectory() : string
8+
public function getConfigDirectoryName() : string
449
{
4510
return 'default_config';
4611
}

features/demo_app/src/KernelWithMethodDocCreatedListener.php

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,14 @@
11
<?php
22
namespace DemoApp;
33

4-
use Symfony\Component\Config\Loader\LoaderInterface;
5-
use Symfony\Component\DependencyInjection\ContainerBuilder;
64
use Symfony\Component\Routing\RouteCollectionBuilder;
75

86
class KernelWithMethodDocCreatedListener extends AbstractKernel
97
{
10-
public function registerBundles(): iterable
11-
{
12-
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
13-
foreach ($contents as $class => $envs) {
14-
if (isset($envs['all']) || isset($envs[$this->environment])) {
15-
yield new $class();
16-
}
17-
}
18-
}
19-
20-
/**
21-
* {@inheritdoc}
22-
*/
23-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
24-
{
25-
$container->setParameter('container.dumper.inline_class_loader', true);
26-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
27-
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
28-
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
29-
}
30-
31-
/**
32-
* {@inheritdoc}
33-
*/
34-
protected function configureRoutes(RouteCollectionBuilder $routes)
35-
{
36-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
37-
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
38-
}
39-
408
/**
419
* {@inheritdoc}
4210
*/
43-
public function getConfigDirectory() : string
11+
public function getConfigDirectoryName() : string
4412
{
4513
return 'config_with_method_doc_created_listener';
4614
}

features/demo_app/src/KernelWithServerDocCreatedListener.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,7 @@
77

88
class KernelWithServerDocCreatedListener extends AbstractKernel
99
{
10-
public function registerBundles(): iterable
11-
{
12-
$contents = require $this->getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php';
13-
foreach ($contents as $class => $envs) {
14-
if (isset($envs['all']) || isset($envs[$this->environment])) {
15-
yield new $class();
16-
}
17-
}
18-
}
19-
20-
/**
21-
* {@inheritdoc}
22-
*/
23-
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
24-
{
25-
$container->setParameter('container.dumper.inline_class_loader', true);
26-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
27-
$loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob');
28-
$loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
29-
}
30-
31-
/**
32-
* {@inheritdoc}
33-
*/
34-
protected function configureRoutes(RouteCollectionBuilder $routes)
35-
{
36-
$confDir = $this->getProjectDir().'/'.$this->getConfigDirectory();
37-
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
38-
}
39-
40-
/**
41-
* {@inheritdoc}
42-
*/
43-
public function getConfigDirectory() : string
10+
public function getConfigDirectoryName() : string
4411
{
4512
return 'config_with_server_doc_created_listener';
4613
}

src/Resources/config/routing/endpoint.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
path="%json_rpc_http_server_doc.http_endpoint_path%/{filename}"
1010
methods="GET"
1111
>
12-
<default key="_controller">json_rpc_http_server_doc.endpoint:httpGet</default>
12+
<default key="_controller">json_rpc_http_server_doc.endpoint::httpGet</default>
1313
<default key="filename">raw.json</default>
1414
</route>
1515
<route
1616
id="json_rpc_http_server_doc_endpoint_options"
1717
path="%json_rpc_http_server_doc.http_endpoint_path%/{filename}"
1818
methods="OPTIONS"
1919
>
20-
<default key="_controller">json_rpc_http_server_doc.endpoint:httpOptions</default>
20+
<default key="_controller">json_rpc_http_server_doc.endpoint::httpOptions</default>
2121
<default key="filename">raw.json</default>
2222
</route>
2323
</routes>

tests/Functional/Creator/HttpServerDocCreatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHPUnit\Framework\TestCase;
55
use Prophecy\Argument;
6+
use Prophecy\PhpUnit\ProphecyTrait;
67
use Prophecy\Prophecy\ObjectProphecy;
78
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
89
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
@@ -16,6 +17,8 @@
1617
*/
1718
class HttpServerDocCreatorTest extends TestCase
1819
{
20+
use ProphecyTrait;
21+
1922
/** @var HttpServerDocCreator */
2023
private $creator;
2124

tests/Functional/DependencyInjection/ConfigFilesTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Tests\Functional\DependencyInjection;
33

4+
use Prophecy\PhpUnit\ProphecyTrait;
45
use Tests\Common\DependencyInjection\AbstractTestClass;
56
use Yoanm\JsonRpcServerDoc\Infra\Normalizer\ErrorDocNormalizer;
67
use Yoanm\JsonRpcServerDoc\Infra\Normalizer\HttpServerDocNormalizer;
@@ -17,10 +18,13 @@
1718

1819
/**
1920
* /!\ This test class does not cover JsonRpcHttpServerDocExtension, it covers yaml configuration files
20-
* => So no [at]covers tag !
21+
* => So no [at]covers tag ! (but @coversNothing is mandatory to avoid failure)
22+
* @coversNothing
2123
*/
2224
class ConfigFilesTest extends AbstractTestClass
2325
{
26+
use ProphecyTrait;
27+
2428
/**
2529
* @dataProvider provideSDKInfraServiceIdAndClass
2630
* @dataProvider provideBundlePublicServiceIdAndClass

tests/Functional/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
55
use PHPUnit\Framework\TestCase;
6+
use Prophecy\PhpUnit\ProphecyTrait;
67
use Yoanm\SymfonyJsonRpcHttpServerDoc\DependencyInjection\Configuration;
78

89
/**
910
* @covers \Yoanm\SymfonyJsonRpcHttpServerDoc\DependencyInjection\Configuration
1011
*/
1112
class ConfigurationTest extends TestCase
1213
{
14+
use ProphecyTrait;
1315
use ConfigurationTestCaseTrait;
1416

1517
protected function getConfiguration()

tests/Functional/DependencyInjection/JsonRpcHttpServerDocExtensionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Tests\Functional\DependencyInjection;
33

4+
use Prophecy\PhpUnit\ProphecyTrait;
45
use Symfony\Component\DependencyInjection\Definition;
56
use Symfony\Component\DependencyInjection\Reference;
67
use Tests\Common\DependencyInjection\AbstractTestClass;
@@ -12,6 +13,8 @@
1213
*/
1314
class JsonRpcHttpServerDocExtensionTest extends AbstractTestClass
1415
{
16+
use ProphecyTrait;
17+
1518
public function testShouldBeLoadable()
1619
{
1720
$this->loadContainer();

0 commit comments

Comments
 (0)