Skip to content

Commit

Permalink
Merge pull request #38 from mybuilder/fix-root_dir-deprecation
Browse files Browse the repository at this point in the history
Fix removed `kernel.root_dir`
  • Loading branch information
rainerkraftmb authored Sep 16, 2020
2 parents 8e74045 + 6b2e735 commit b384882
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Kernel;

class Configuration implements ConfigurationInterface
{
Expand All @@ -19,6 +20,14 @@ public function getConfigTreeBuilder(): TreeBuilder
$rootNode = $treeBuilder->root('my_builder_cronos');
}

if (method_exists(Kernel::class, 'getProjectDir')) {
// `kernel.project_dir` available since Symfony 3.3
$pathToConsole = '%kernel.project_dir%/bin/console';
} else {
// `kernel.root_dir` dropped in Symfony 5
$pathToConsole = '%kernel.root_dir%/../bin/console';
}

$rootNode
->children()
->arrayNode('exporter')
Expand Down Expand Up @@ -47,7 +56,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->scalarNode('console')
->cannotBeEmpty()
->defaultValue('%kernel.root_dir%/../bin/console')
->defaultValue($pathToConsole)
->example('%kernel.project_dir%/bin/console')
->info('Allows you to specify the console that all commands should be passed to such as "bin/console".')
->end()
Expand Down
9 changes: 8 additions & 1 deletion Tests/DependencyInjection/MyBuilderCronosExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Yaml\Yaml;

class MyBuilderCronosExtensionTest extends TestCase
Expand Down Expand Up @@ -34,11 +35,17 @@ public function test_config(array $expected, string $file): void

public function providerTestConfig(): array
{
if (method_exists(Kernel::class, 'getProjectDir')) {
$pathToConsole = '%kernel.project_dir%/bin/console';
} else {
$pathToConsole = '%kernel.root_dir%/../bin/console';
}

return [
[
[
'executor' => 'php',
'console' => '%kernel.root_dir%/../bin/console',
'console' => $pathToConsole,
],
'empty.yml',
],
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
"mybuilder/cronos": "~3.0",
"doctrine/annotations": "1.*",
"symfony/console": "~3.0||^4.0||^5.0",
"symfony/config": "~3.0||^4.0||^5.0",
"symfony/dependency-injection": "~3.0||^4.0||^5.0",
"symfony/framework-bundle": "~3.0||^4.0||^5.0",
"symfony/yaml": "3.0||^4.0||^5.0",
"symfony/http-kernel": "~3.0||^4.0||^5.0",
"symfony/yaml": "~3.0||^4.0||^5.0",
"symfony/property-access": "~3.0||^4.0||^5.0",
"php": ">=7.3"
},
Expand Down

0 comments on commit b384882

Please sign in to comment.