Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to dump the config reference #452

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -12,10 +12,6 @@ matrix:
allow_failures:
- php: hhvm
include:
- php: 5.5
env: SYMFONY_VERSION='2.1.*'
- php: 5.5
env: SYMFONY_VERSION='2.2.*'
- php: 5.5
env: SYMFONY_VERSION='2.3.*'

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -18,7 +18,7 @@
"behat/gherkin": "~4.0",
"behat/transliterator": "~1.0",
"symfony/console": "~2.1",
"symfony/config": "~2.1",
"symfony/config": "~2.3",
"symfony/dependency-injection": "~2.1",
"symfony/event-dispatcher": "~2.1",
"symfony/translation": "~2.1",
Expand Down
2 changes: 1 addition & 1 deletion features/bootstrap/FeatureContext.php
Expand Up @@ -192,7 +192,7 @@ public function theOutputShouldContain(PyStringNode $text)

private function getExpectedOutput(PyStringNode $expectedText)
{
$text = strtr($expectedText, array('\'\'\'' => '"""'));
$text = strtr($expectedText, array('\'\'\'' => '"""', '%%TMP_DIR%%' => sys_get_temp_dir() . DIRECTORY_SEPARATOR));

// windows path fix
if ('/' !== DIRECTORY_SEPARATOR) {
Expand Down
146 changes: 146 additions & 0 deletions features/config_reference.feature
@@ -0,0 +1,146 @@
Feature: Config reference
In order to know the available configuration
As a Behat user
I need to be able to dump the configuration reference

Scenario: Reference of defaults extension
When I run "behat --no-colors --config-reference -v"
Then it should pass with:
"""
testwork:
cli: []
calls:
error_reporting: 32767
suites:

# Prototype
name:
enabled: true
type: null
settings:

# Prototype
name: ~
environments: []
specifications: []
events: []
filesystem: []
exceptions: []
autoload:

# Default:
: %paths.base%/features/bootstrap
translation:
locale: en
fallback_locale: en
gherkin:
cache: %%TMP_DIR%%gherkin_cache
filters:

# Prototype
name: ~
contexts: []
formatters:

# Prototype
name: []
snippets: []
definitions: []
hooks: []
transformations: []
testers:
strict: false
skip: false
"""

Scenario: Custom extension
Given a file named "behat.yml" with:
"""
default:
extensions:
custom_extension.php: ~
"""
And a file named "custom_extension.php" with:
"""
<?php

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class CustomExtension implements Behat\Testwork\ServiceContainer\Extension {
public function getConfigKey()
{
return 'custom_extension';
}

public function configure(ArrayNodeDefinition $builder)
{
$builder
->children()
->scalarNode('child')->info('A child node')->end()
->booleanNode('test')->defaultTrue()->end()
->end();
}

public function initialize(Behat\Testwork\ServiceContainer\ExtensionManager $extensionManager) {}

public function load(ContainerBuilder $container, array $config) {}

public function process(ContainerBuilder $container) {}
}

return new CustomExtension;
"""
When I run "behat --no-colors --config-reference"
Then it should pass with:
"""
testwork:
cli: []
calls:
error_reporting: 32767
suites:

# Prototype
name:
enabled: true
type: null
settings:

# Prototype
name: ~
environments: []
specifications: []
events: []
filesystem: []
exceptions: []
autoload:

# Default:
: %paths.base%/features/bootstrap
translation:
locale: en
fallback_locale: en
gherkin:
cache: %%TMP_DIR%%gherkin_cache
filters:

# Prototype
name: ~
contexts: []
formatters:

# Prototype
name: []
snippets: []
definitions: []
hooks: []
transformations: []
testers:
strict: false
skip: false
custom_extension:

# A child node
child: ~
test: true
"""
2 changes: 1 addition & 1 deletion src/Behat/Testwork/Call/ServiceContainer/CallExtension.php
Expand Up @@ -74,7 +74,7 @@ public function configure(ArrayNodeDefinition $builder)
$builder
->addDefaultsIfNotSet()
->children()
->scalarNode('error_reporting')->defaultValue(E_ALL)
->scalarNode('error_reporting')->defaultValue(E_ALL | E_STRICT)
->end()
;
}
Expand Down
25 changes: 22 additions & 3 deletions src/Behat/Testwork/Cli/Application.php
Expand Up @@ -15,6 +15,7 @@
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -48,10 +49,10 @@ final class Application extends BaseApplication
*/
public function __construct($name, $version, ConfigurationLoader $configLoader, ExtensionManager $extensionManager)
{
parent::__construct($name, $version);

$this->configurationLoader = $configLoader;
$this->extensionManager = $extensionManager;

parent::__construct($name, $version);
}

/**
Expand All @@ -66,6 +67,7 @@ public function getDefaultInputDefinition()
new InputOption('--config', '-c', InputOption::VALUE_REQUIRED, 'Specify config file to use.'),
new InputOption('--verbose', '-v', InputOption::VALUE_NONE, 'Increase verbosity of exceptions.'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message.'),
new InputOption('--config-reference', null, InputOption::VALUE_NONE, 'Display the configuration reference.'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this behat version.'),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question.'),
));
Expand All @@ -87,7 +89,20 @@ public function doRun(InputInterface $input, OutputInterface $output)

$this->add($this->createCommand($input, $output));

return BaseApplication::doRun($input, $output);
if ($input->hasParameterOption(array('--config-reference'))) {
$input = new ArrayInput(array('--config-reference' => true));
}

return parent::doRun($input, $output);
}

protected function getDefaultCommands()
{
$commands = parent::getDefaultCommands();

$commands[] = new DumpReferenceCommand($this->extensionManager);

return $commands;
}

/**
Expand Down Expand Up @@ -168,6 +183,10 @@ private function getBasePath()
*/
protected function getCommandName(InputInterface $input)
{
if ($input->hasParameterOption(array('--config-reference'))) {
return 'dump-reference';
}

return $this->getName();
}
}
45 changes: 45 additions & 0 deletions src/Behat/Testwork/Cli/DumpReferenceCommand.php
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the Behat Testwork.
* (c) Konstantin Kudryashov <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Behat\Testwork\Cli;

use Behat\Testwork\ServiceContainer\Configuration\ConfigurationTree;
use Behat\Testwork\ServiceContainer\ExtensionManager;
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
use Symfony\Component\Config\Definition\ReferenceDumper;
use Symfony\Component\Console\Command\Command as BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class DumpReferenceCommand extends BaseCommand
{
private $extensionManager;

public function __construct(ExtensionManager $extensionManager)
{
$this->extensionManager = $extensionManager;

parent::__construct('dump-reference');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
if (class_exists('Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper')) {
$dumper = new YamlReferenceDumper();
} else {
// Support Symfony Config 2.3
$dumper = new ReferenceDumper();
}

$configTree = new ConfigurationTree();

$output->writeln($dumper->dumpNode($configTree->getConfigTree($this->extensionManager->getExtensions())));
}
}