8000 Rename custom methods and properties (#57) · jderusse/symfony-bundle-test@25420f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 25420f8

Browse files
authored
Rename custom methods and properties (SymfonyTest#57)
BREAKING CHANGE: Renamed all custom methods and properties to better differ from what is from symfony itself and what is part of the test kernel.
1 parent 5ce337b commit 25420f8

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BundleInitializationTest extends KernelTestCase
4242
* @var TestKernel $kernel
4343
*/
4444
$kernel = parent::createKernel($options);
45-
$kernel->addBundle(AcmeFooBundle::class);
45+
$kernel->addTestBundle(AcmeFooBundle::class);
4646
$kernel->handleOptions($options);
4747

4848
return $kernel;
@@ -59,21 +59,21 @@ class BundleInitializationTest extends KernelTestCase
5959
// Or for FrameworkBundle@^5.3.6 to access private services without the PublicCompilerPass
6060
// $container = self::getContainer();
6161

62-
// Test if you services exists
62+
// Test if your services exists
6363
$this->assertTrue($container->has('acme.foo'));
6464
$service = $container->get('acme.foo');
6565
$this->assertInstanceOf(Foo::class, $service);
6666
}
6767

6868
public function testBundleWithDifferentConfiguration(): void
6969
{
70-
// Boot the kernel as normal ...
70+
// Boot the kernel with a config closure, the handleOptions call in createKernel is important for that to work
7171
$kernel = self::bootKernel(['config' => static function(TestKernel $kernel){
7272
// Add some other bundles we depend on
73-
$kernel->addBundle(OtherBundle::class);
73+
$kernel->addTestBundle(OtherBundle::class);
7474

7575
// Add some configuration
76-
$kernel->addConfig(__DIR__.'/config.yml');
76+
$kernel->addTestConfig(__DIR__.'/config.yml');
7777
}]);
7878

7979
// ...

src/TestKernel.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@ class TestKernel extends Kernel
2323
/**
2424
* @var string[]
2525
*/
26-
private $bundlesToRegister = [];
26+
private $testBundle = [];
2727

2828
/**
2929
* @var string[]|callable[]
3030
*/
31-
private $configs = [];
31+
private $testConfigs = [];
3232

3333
/**
3434
* @var string
3535
*/
36-
private $cachePrefix;
36+
private $testCachePrefix;
3737

3838
/**
3939
* @var string|null;
4040
*/
41-
private $fakedProjectDir;
41+
private $testProjectDir;
4242

4343
/**
4444
* @var CompilerPassInterface[]
4545
*/
46-
private $compilerPasses = [];
46+
private $testCompilerPasses = [];
4747

4848
/**
4949
* @var array<int, string>
5050
*/
51-
private $routingFiles = [];
51+
private $testRoutingFiles = [];
5252

5353
/**
5454
* {@inheritDoc}
@@ -57,14 +57,14 @@ public function __construct(string $environment, bool $debug)
5757
{
5858
parent::__construct($environment, $debug);
5959

60-
$this->cachePrefix = uniqid('cache', true);
60+
$this->testCachePrefix = uniqid('cache', true);
6161

62-
$this->addBundle(FrameworkBundle::class);
63-
$this->addConfig(__DIR__.'/config/framework.yml');
62+
$this->addTestBundle(FrameworkBundle::class);
63+
$this->addTestConfig(__DIR__.'/config/framework.yml');
6464
if (class_exists(ConfigBuilderCacheWarmer::class)) {
65-
$this->addConfig(__DIR__.'/config/framework-53.yml');
65+
$this->addTestConfig(__DIR__.'/config/framework-53.yml');
6666
} else {
67-
$this->addConfig(__DIR__.'/config/framework-52.yml');
67+
$this->addTestConfig(__DIR__.'/config/framework-52.yml');
6868
}
6969
}
7070

@@ -73,22 +73,22 @@ public function __construct(string $environment, bool $debug)
7373
*
7474
* @param string $bundleClassName
7575
*/
76-
public function addBundle($bundleClassName): void
76+
public function addTestBundle($bundleClassName): void
7777
{
78-
$this->bundlesToRegister[] = $bundleClassName;
78+
$this->testBundle[] = $bundleClassName;
7979
}
8080

8181
/**
8282
* @param string|callable $configFile path to a config file or a callable which get the {@see ContainerBuilder} as its first argument
8383
*/
84-
public function addConfig($configFile): void
84+
public function addTestConfig($configFile): void
8585
{
86-
$this->configs[] = $configFile;
86+
$this->testConfigs[] = $configFile;
8787
}
8888

8989
public function getCacheDir(): string
9090
{
91-
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/'.$this->cachePrefix;
91+
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/'.$this->testCachePrefix;
9292
}
9393

9494
public function getLogDir(): string
@@ -98,26 +98,26 @@ public function getLogDir(): string
9898

9999
public function getProjectDir(): string
100100
{
101-
if (null === $this->fakedProjectDir) {
101+
if (null === $this->testProjectDir) {
102102
return realpath(__DIR__.'/../../../../');
103103
}
104104

105-
return $this->fakedProjectDir;
105+
return $this->testProjectDir;
106106
}
107107

108108
/**
109109
* @param string|null $projectDir
110110
*/
111-
public function setProjectDir($projectDir): void
111+
public function setTestProjectDir($projectDir): void
112112
{
113-
$this->fakedProjectDir = $projectDir;
113+
$this->testProjectDir = $projectDir;
114114
}
115115

116116
public function registerBundles(): iterable
117117
{
118-
$this->bundlesToRegister = array_unique($this->bundlesToRegister);
118+
$this->testBundle = array_unique($this->testBundle);
119119

120-
foreach ($this->bundlesToRegister as $bundle) {
120+
foreach ($this->testBundle as $bundle) {
121121
yield new $bundle();
122122
}
123123
}
@@ -129,7 +129,7 @@ protected function buildContainer(): ContainerBuilder
129129
{
130130
$container = parent::buildContainer();
131131

132-
foreach ($this->compilerPasses as $pass) {
132+
foreach ($this->testCompilerPasses as $pass) {
133133
$container->addCompilerPass($pass);
134134
}
135135

@@ -139,17 +139,17 @@ protected function buildContainer(): ContainerBuilder
139139
/**
140140
* @param CompilerPassInterface $compilerPasses
141141
*/
142-
public function addCompilerPass($compilerPasses): void
142+
public function addTestCompilerPass($compilerPasses): void
143143
{
144-
$this->compilerPasses[] = $compilerPasses;
144+
$this->testCompilerPasses[] = $compilerPasses;
145145
}
146146

147147
/**
148148
* @param string $routingFile
149149
*/
150-
public function addRoutingFile($routingFile): void
150+
public function addTestRoutingFile($routingFile): void
151151
{
152-
$this->routingFiles[] = $routingFile;
152+
$this->testRoutingFiles[] = $routingFile;
153153
}
154154

155155
public function handleOptions(array $options): void
@@ -165,7 +165,7 @@ public function handleOptions(array $options): void
165165
*/
166166
protected function configureContainer($container, $loader): void
167167
{
168-
foreach ($this->configs as $config) {
168+
foreach ($this->testConfigs as $config) {
169169
$loader->load($config);
170170
}
171171
}
@@ -175,7 +175,7 @@ protected function configureContainer($container, $loader): void
175175
*/
176176
protected function configureRoutes($routes): void
177177
{
178-
foreach ($this->routingFiles as $routingFile) {
178+
foreach ($this->testRoutingFiles as $routingFile) {
179179
$routes->import($routingFile);
180180
}
181181
}

tests/Functional/BundleConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected static function createKernel(array $options = []): KernelInterface
2424
* @var TestKernel $kernel
2525
*/
2626
$kernel = parent::createKernel($options);
27-
$kernel->addBundle(ConfigurationBundle::class);
27+
$kernel->addTestBundle(ConfigurationBundle::class);
2828
$kernel->handleOptions($options);
2929

3030
return $kernel;
@@ -53,7 +53,7 @@ public function provideBundleWithDifferentConfigurationFormats(): array
5353
public function testBundleWithDifferentConfigurationFormats($config): void
5454
{
5555
$kernel = self::bootKernel(['config' => function (TestKernel $kernel) use ($config) {
56-
$kernel->addConfig($config);
56+
$kernel->addTestConfig($config);
5757
}]);
5858

5959
$container = $kernel->getContainer();

tests/Functional/BundleInitializationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected static function createKernel(array $options = []): KernelInterface
2323
* @var TestKernel $kernel
2424
*/
2525
$kernel = parent::createKernel($options);
26-
$kernel->addBundle(FrameworkBundle::class);
26+
$kernel->addTestBundle(FrameworkBundle::class);
2727

2828
return $kernel;
2929
}

tests/Functional/BundleRoutingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testAddRoutingFile(): void
2929
{
3030
$kernel = self::bootKernel([
3131
'config' => static function (TestKernel $kernel) {
32-
$kernel->addRoutingFile(__DIR__.'/../Fixtures/Resources/Routing/routes.yml');
32+
$kernel->addTestRoutingFile(__DIR__.'/../Fixtures/Resources/Routing/routes.yml');
3333
},
3434
]);
3535

0 commit comments

Comments
 (0)
0