Skip to content

Commit 3476683

Browse files
committed
Tests: Abstracting TestKernel
1 parent 48128bb commit 3476683

File tree

4 files changed

+45
-71
lines changed

4 files changed

+45
-71
lines changed

Tests/DependencyInjection/OverblogGraphiQLExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ private function createContainer()
5353

5454
private function compileContainer(ContainerBuilder $container)
5555
{
56-
$container->getCompilerPassConfig()->setOptimizationPasses(array());
57-
$container->getCompilerPassConfig()->setRemovingPasses(array());
56+
$container->getCompilerPassConfig()->setOptimizationPasses([]);
57+
$container->getCompilerPassConfig()->setRemovingPasses([]);
5858
$container->compile();
5959
}
6060
}

Tests/Fixtures/TestKernel.php

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
namespace Overblog\GraphiQLBundle\Tests\Fixtures;
44

55
use Overblog\GraphiQLBundle\OverblogGraphiQLBundle;
6+
use Overblog\GraphiQLBundle\Tests\TestKernel as AbstractTestKernel;
67
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
78
use Symfony\Bundle\TwigBundle\TwigBundle;
89
use Symfony\Component\Config\Loader\LoaderInterface;
910
use Symfony\Component\DependencyInjection\ContainerBuilder;
10-
use Symfony\Component\HttpKernel\Kernel;
1111

12-
final class TestKernel extends Kernel
12+
final class TestKernel extends AbstractTestKernel
1313
{
14-
private $testCase;
15-
16-
/**
17-
* {@inheritdoc}
18-
*/
1914
public function registerBundles()
2015
{
2116
return [
@@ -25,34 +20,8 @@ public function registerBundles()
2520
];
2621
}
2722

28-
public function __construct($environment, $debug, $testCase = null)
29-
{
30-
$this->testCase = null !== $testCase ? $testCase : false;
31-
parent::__construct($environment, $debug);
32-
}
33-
34-
public function getCacheDir()
35-
{
36-
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
37-
}
38-
39-
public function getLogDir()
40-
{
41-
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
42-
}
43-
44-
public function getRootDir()
45-
{
46-
return __DIR__;
47-
}
48-
49-
public function isBooted()
50-
{
51-
return $this->booted;
52-
}
53-
5423
/**
55-
* {@inheritdoc}
24+
* @inheritdoc
5625
*/
5726
public function registerContainerConfiguration(LoaderInterface $loader)
5827
{
@@ -62,7 +31,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6231
'test' => true,
6332
'templating' => ['engine' => ['twig']],
6433
'assets' => ['enabled' => false],
65-
'router' => ['resource' => '%kernel.root_dir%/../../Resources/config/routing.xml'],
34+
'router' => ['resource' => '%kernel.root_dir%/../Resources/config/routing.xml'],
6635
]);
6736
});
6837
}

Tests/Integration/OverblogGraphQLBundle/Fixtures/TestKernel.php

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44

55
use Overblog\GraphiQLBundle\OverblogGraphiQLBundle;
66
use Overblog\GraphQLBundle\OverblogGraphQLBundle;
7+
use Overblog\GraphiQLBundle\Tests\TestKernel as AbstractTestKernel;
78
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
89
use Symfony\Bundle\TwigBundle\TwigBundle;
910
use Symfony\Component\Config\Loader\LoaderInterface;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
11-
use Symfony\Component\HttpKernel\Kernel;
1212

13-
final class TestKernel extends Kernel
13+
final class TestKernel extends AbstractTestKernel
1414
{
15-
private $testCase;
16-
17-
/**
18-
* {@inheritdoc}
19-
*/
2015
public function registerBundles()
2116
{
2217
return [
@@ -27,32 +22,6 @@ public function registerBundles()
2722
];
2823
}
2924

30-
public function __construct($environment, $debug, $testCase = null)
31-
{
32-
$this->testCase = null !== $testCase ? $testCase : false;
33-
parent::__construct($environment, $debug);
34-
}
35-
36-
public function getCacheDir()
37-
{
38-
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
39-
}
40-
41-
public function getLogDir()
42-
{
43-
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
44-
}
45-
46-
public function getRootDir()
47-
{
48-
return __DIR__;
49-
}
50-
51-
public function isBooted()
52-
{
53-
return $this->booted;
54-
}
55-
5625
/**
5726
* {@inheritdoc}
5827
*/
@@ -65,7 +34,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
6534
'templating' => ['engine' => ['twig']],
6635
'assets' => ['enabled' => false],
6736
'router' => [
68-
'resource' => '%kernel.root_dir%/Resources/config/routing.xml',
37+
'resource' => __DIR__ . '/Resources/config/routing.xml',
6938
],
7039
]);
7140
});

Tests/TestKernel.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Overblog\GraphiQLBundle\Tests;
4+
5+
use Symfony\Component\HttpKernel\Kernel;
6+
7+
abstract class TestKernel extends Kernel
8+
{
9+
private $testCase;
10+
11+
public function __construct($environment, $debug, $testCase = null)
12+
{
13+
$this->testCase = null !== $testCase ? $testCase : false;
14+
parent::__construct($environment, $debug);
15+
}
16+
17+
public function getCacheDir()
18+
{
19+
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/cache/'.$this->environment;
20+
}
21+
22+
public function getLogDir()
23+
{
24+
return sys_get_temp_dir().'/OverblogGraphQLBundle/'.Kernel::VERSION.'/'.$this->testCase.'/logs';
25+
}
26+
27+
public function getRootDir()
28+
{
29+
return __DIR__;
30+
}
31+
32+
public function isBooted()
33+
{
34+
return $this->booted;
35+
}
36+
}

0 commit comments

Comments
 (0)