Skip to content

Commit

Permalink
Rename custom methods and properties (#57)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chapterjason authored Aug 24, 2021
1 parent 5ce337b commit 25420f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BundleInitializationTest extends KernelTestCase
* @var TestKernel $kernel
*/
$kernel = parent::createKernel($options);
$kernel->addBundle(AcmeFooBundle::class);
$kernel->addTestBundle(AcmeFooBundle::class);
$kernel->handleOptions($options);

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

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

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

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

// ...
Expand Down
58 changes: 29 additions & 29 deletions src/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ class TestKernel extends Kernel
/**
* @var string[]
*/
private $bundlesToRegister = [];
private $testBundle = [];

/**
* @var string[]|callable[]
*/
private $configs = [];
private $testConfigs = [];

/**
* @var string
*/
private $cachePrefix;
private $testCachePrefix;

/**
* @var string|null;
*/
private $fakedProjectDir;
private $testProjectDir;

/**
* @var CompilerPassInterface[]
*/
private $compilerPasses = [];
private $testCompilerPasses = [];

/**
* @var array<int, string>
*/
private $routingFiles = [];
private $testRoutingFiles = [];

/**
* {@inheritDoc}
Expand All @@ -57,14 +57,14 @@ public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);

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

$this->addBundle(FrameworkBundle::class);
$this->addConfig(__DIR__.'/config/framework.yml');
$this->addTestBundle(FrameworkBundle::class);
$this->addTestConfig(__DIR__.'/config/framework.yml');
if (class_exists(ConfigBuilderCacheWarmer::class)) {
$this->addConfig(__DIR__.'/config/framework-53.yml');
$this->addTestConfig(__DIR__.'/config/framework-53.yml');
} else {
$this->addConfig(__DIR__.'/config/framework-52.yml');
$this->addTestConfig(__DIR__.'/config/framework-52.yml');
}
}

Expand All @@ -73,22 +73,22 @@ public function __construct(string $environment, bool $debug)
*
* @param string $bundleClassName
*/
public function addBundle($bundleClassName): void
public function addTestBundle($bundleClassName): void
{
$this->bundlesToRegister[] = $bundleClassName;
$this->testBundle[] = $bundleClassName;
}

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

public function getCacheDir(): string
{
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/'.$this->cachePrefix;
return realpath(sys_get_temp_dir()).'/NyholmBundleTest/'.$this->testCachePrefix;
}

public function getLogDir(): string
Expand All @@ -98,26 +98,26 @@ public function getLogDir(): string

public function getProjectDir(): string
{
if (null === $this->fakedProjectDir) {
if (null === $this->testProjectDir) {
return realpath(__DIR__.'/../../../../');
}

return $this->fakedProjectDir;
return $this->testProjectDir;
}

/**
* @param string|null $projectDir
*/
public function setProjectDir($projectDir): void
public function setTestProjectDir($projectDir): void
{
$this->fakedProjectDir = $projectDir;
$this->testProjectDir = $projectDir;
}

public function registerBundles(): iterable
{
$this->bundlesToRegister = array_unique($this->bundlesToRegister);
$this->testBundle = array_unique($this->testBundle);

foreach ($this->bundlesToRegister as $bundle) {
foreach ($this->testBundle as $bundle) {
yield new $bundle();
}
}
Expand All @@ -129,7 +129,7 @@ protected function buildContainer(): ContainerBuilder
{
$container = parent::buildContainer();

foreach ($this->compilerPasses as $pass) {
foreach ($this->testCompilerPasses as $pass) {
$container->addCompilerPass($pass);
}

Expand All @@ -139,17 +139,17 @@ protected function buildContainer(): ContainerBuilder
/**
* @param CompilerPassInterface $compilerPasses
*/
public function addCompilerPass($compilerPasses): void
public function addTestCompilerPass($compilerPasses): void
{
$this->compilerPasses[] = $compilerPasses;
$this->testCompilerPasses[] = $compilerPasses;
}

/**
* @param string $routingFile
*/
public function addRoutingFile($routingFile): void
public function addTestRoutingFile($routingFile): void
{
$this->routingFiles[] = $routingFile;
$this->testRoutingFiles[] = $routingFile;
}

public function handleOptions(array $options): void
Expand All @@ -165,7 +165,7 @@ public function handleOptions(array $options): void
*/
protected function configureContainer($container, $loader): void
{
foreach ($this->configs as $config) {
foreach ($this->testConfigs as $config) {
$loader->load($config);
}
}
Expand All @@ -175,7 +175,7 @@ protected function configureContainer($container, $loader): void
*/
protected function configureRoutes($routes): void
{
foreach ($this->routingFiles as $routingFile) {
foreach ($this->testRoutingFiles as $routingFile) {
$routes->import($routingFile);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/BundleConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected static function createKernel(array $options = []): KernelInterface
* @var TestKernel $kernel
*/
$kernel = parent::createKernel($options);
$kernel->addBundle(ConfigurationBundle::class);
$kernel->addTestBundle(ConfigurationBundle::class);
$kernel->handleOptions($options);

return $kernel;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function provideBundleWithDifferentConfigurationFormats(): array
public function testBundleWithDifferentConfigurationFormats($config): void
{
$kernel = self::bootKernel(['config' => function (TestKernel $kernel) use ($config) {
$kernel->addConfig($config);
$kernel->addTestConfig($config);
}]);

$container = $kernel->getContainer();
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected static function createKernel(array $options = []): KernelInterface
* @var TestKernel $kernel
*/
$kernel = parent::createKernel($options);
$kernel->addBundle(FrameworkBundle::class);
$kernel->addTestBundle(FrameworkBundle::class);

return $kernel;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/BundleRoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testAddRoutingFile(): void
{
$kernel = self::bootKernel([
'config' => static function (TestKernel $kernel) {
$kernel->addRoutingFile(__DIR__.'/../Fixtures/Resources/Routing/routes.yml');
$kernel->addTestRoutingFile(__DIR__.'/../Fixtures/Resources/Routing/routes.yml');
},
]);

Expand Down

0 comments on commit 25420f8

Please sign in to comment.