Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added an option to dump the config reference #452

Closed
wants to merge 5 commits into from

2 participants

@stof
Owner

As promised before my vacations, here is the config reference dumping.

The ReferenceDumper class is deprecated as of Symfony 2.4 (scheduled for removal in 3.0) becuse of the introduction of the XML dumping support in 2.4 (the deprecated class extends the new class). However, I'm using it here to keep the support of Symfony 2.3 without doing a class_exists check for the new class.

A next step for this will be to provide some description of the config for nodes where it makes sense (see the custom extension in the feature file)

@everzet
Owner

@stof I kinda missed this one :( Could you rebase it???

@everzet everzet added this to the 3.0.0 milestone
@everzet everzet added the feature label
@stof stof was assigned by everzet
@stof
Owner

There was no need to rebase it. It was already rebased on the latest 3.0 branch. However, I pushed a few more changes

@stof
Owner

OK, tests are failing on Symfony 2.3 (and on my Windows machine with 2.4) because of small differences in the output of the reference dumper. How would you handle it ?

@everzet
Owner

@stof I see two options:

  1. optimize string difference inside context before comparing (easier)
  2. define different feature files for different environments with different tags (harder)
@everzet
Owner

@stof news? Do you want me to carry on from this point?

@stof
Owner

if you have time for it, yeah it would be good

stof added some commits
@stof stof Added an option to dump the config reference f1f578b
@stof stof Fixed use statement conflict 418c5d5
@stof stof Fixed the feature on Unix systems
The Yaml dumper is quoting values containing a space but not values
without spaces. The default temp folder does not have a space on Unix
systems, while it depends on the user name on Windows.
a51f9bc
@stof stof Removed usage of the deprecated class on Symfony 2.4+ 84daaf5
@stof stof Ensured a consistent default error reporting level for PHP 5.4 and 5.5
E_ALL includes E_STRICT as of PHP 5.5 but it was not the case in PHP 5.3
and 5.4. The default value for the error reporting now includes E_STRICT
for all versions to be consistent.
a448e4e
@stof
Owner

@everzet I rebased my branch to fix the conflicts. However, it would be great if you have time to fix the testsuite

@everzet
Owner

@stof leave the test suite on me ;)

@stof
Owner

I think we should find a way to write the feature without relying on the exact format of the reference output, as we don't control it. This will avoid the pain of handling formatting changes between Symfony 2.3 and 2.4, and also avoid the pain of having to update these scenario neach time we alter the config a bit in Behat

@everzet
Owner

Close in favour of #496

@everzet everzet closed this
@stof stof deleted the stof:config_reference branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 6, 2014
  1. @stof
  2. @stof

    Fixed use statement conflict

    stof authored
  3. @stof

    Fixed the feature on Unix systems

    stof authored
    The Yaml dumper is quoting values containing a space but not values
    without spaces. The default temp folder does not have a space on Unix
    systems, while it depends on the user name on Windows.
  4. @stof
  5. @stof

    Ensured a consistent default error reporting level for PHP 5.4 and 5.5

    stof authored
    E_ALL includes E_STRICT as of PHP 5.5 but it was not the case in PHP 5.3
    and 5.4. The default value for the error reporting now includes E_STRICT
    for all versions to be consistent.
This page is out of date. Refresh to see the latest.
View
4 .travis.yml
@@ -13,10 +13,6 @@ matrix:
- 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.*'
before_script:
View
2  composer.json
@@ -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",
View
2  features/bootstrap/FeatureContext.php
@@ -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) {
View
146 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
+ """
View
2  src/Behat/Testwork/Call/ServiceContainer/CallExtension.php
@@ -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()
;
}
View
25 src/Behat/Testwork/Cli/Application.php
@@ -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;
@@ -48,10 +49,10 @@
*/
public function __construct($name, $version, ConfigurationLoader $configLoader, ExtensionManager $extensionManager)
{
- parent::__construct($name, $version);
-
$this->configurationLoader = $configLoader;
$this->extensionManager = $extensionManager;
+
+ parent::__construct($name, $version);
}
/**
@@ -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.'),
));
@@ -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;
}
/**
@@ -168,6 +183,10 @@ private function getBasePath()
*/
protected function getCommandName(InputInterface $input)
{
+ if ($input->hasParameterOption(array('--config-reference'))) {
+ return 'dump-reference';
+ }
+
return $this->getName();
}
}
View
45 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())));
+ }
+}
Something went wrong with that request. Please try again.