Skip to content
Browse files

merged branch dirkaholic/testDefaultInputDefintion (PR #5668)

This PR was squashed before being merged into the master branch (closes #5668).

Commits
-------

1117499 [2.2][Console] Test default input defintion and default helper set

Discussion
----------

[2.2][Console] Test default input defintion and default helper set

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
License of the code: MIT
Documentation PR: -

See: symfony/symfony#5638
  • Loading branch information...
2 parents ecad7ff + b64f659 commit 452df2b15dfc81aa483705d434c13c8eaf194c8f @fabpot fabpot committed Oct 4, 2012
Showing with 114 additions and 0 deletions.
  1. +114 −0 Tests/ApplicationTest.php
View
114 Tests/ApplicationTest.php
@@ -12,8 +12,11 @@
namespace Symfony\Component\Console\Tests;
use Symfony\Component\Console\Application;
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\Output;
@@ -506,4 +509,115 @@ public function getAddingAlreadySetDefinitionElementData()
array(new InputOption('query', 'q', InputOption::VALUE_NONE)),
);
}
+
+ public function testGetDefaultHelperSetReturnsDefaultValues()
+ {
+ $application = new Application();
+ $application->setAutoExit(false);
+ $application->setCatchExceptions(false);
+
+ $helperSet = $application->getHelperSet();
+
+ $this->assertTrue($helperSet->has('formatter'));
+ $this->assertTrue($helperSet->has('dialog'));
+ $this->assertTrue($helperSet->has('progress'));
+ }
+
+ public function testAddingSingleHelperSetOverwritesDefaultValues()
+ {
+ $application = new Application();
+ $application->setAutoExit(false);
+ $application->setCatchExceptions(false);
+
+ $application->setHelperSet(new HelperSet(array(new FormatterHelper())));
+
+ $helperSet = $application->getHelperSet();
+
+ $this->assertTrue($helperSet->has('formatter'));
+
+ // no other default helper set should be returned
+ $this->assertFalse($helperSet->has('dialog'));
+ $this->assertFalse($helperSet->has('progress'));
+ }
+
+ public function testOverwritingDefaultHelperSetOverwritesDefaultValues()
+ {
+ $application = new CustomApplication();
+ $application->setAutoExit(false);
+ $application->setCatchExceptions(false);
+
+ $application->setHelperSet(new HelperSet(array(new FormatterHelper())));
+
+ $helperSet = $application->getHelperSet();
+
+ $this->assertTrue($helperSet->has('formatter'));
+
+ // no other default helper set should be returned
+ $this->assertFalse($helperSet->has('dialog'));
+ $this->assertFalse($helperSet->has('progress'));
+ }
+
+ public function testGetDefaultInputDefinitionReturnsDefaultValues()
+ {
+ $application = new Application();
+ $application->setAutoExit(false);
+ $application->setCatchExceptions(false);
+
+ $inputDefinition = $application->getDefinition();
+
+ $this->assertTrue($inputDefinition->hasArgument('command'));
+
+ $this->assertTrue($inputDefinition->hasOption('help'));
+ $this->assertTrue($inputDefinition->hasOption('quiet'));
+ $this->assertTrue($inputDefinition->hasOption('verbose'));
+ $this->assertTrue($inputDefinition->hasOption('version'));
+ $this->assertTrue($inputDefinition->hasOption('ansi'));
+ $this->assertTrue($inputDefinition->hasOption('no-ansi'));
+ $this->assertTrue($inputDefinition->hasOption('no-interaction'));
+ }
+
+ public function testOverwritingDefaultInputDefinitionOverwritesDefaultValues()
+ {
+ $application = new CustomApplication();
+ $application->setAutoExit(false);
+ $application->setCatchExceptions(false);
+
+ $inputDefinition = $application->getDefinition();
+
+ // check wether the default arguments and options are not returned any more
+ $this->assertFalse($inputDefinition->hasArgument('command'));
+
+ $this->assertFalse($inputDefinition->hasOption('help'));
+ $this->assertFalse($inputDefinition->hasOption('quiet'));
+ $this->assertFalse($inputDefinition->hasOption('verbose'));
+ $this->assertFalse($inputDefinition->hasOption('version'));
+ $this->assertFalse($inputDefinition->hasOption('ansi'));
+ $this->assertFalse($inputDefinition->hasOption('no-ansi'));
+ $this->assertFalse($inputDefinition->hasOption('no-interaction'));
+
+ $this->assertTrue($inputDefinition->hasOption('custom'));
+ }
}
+
+class CustomApplication extends Application
+{
+ /**
+ * Overwrites the default input definition.
+ *
+ * @return InputDefinition An InputDefinition instance
+ */
+ protected function getDefaultInputDefinition()
+ {
+ return new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')));
+ }
+
+ /**
+ * Gets the default helper set with the helpers that should always be available.
+ *
+ * @return HelperSet A HelperSet instance
+ */
+ protected function getDefaultHelperSet()
+ {
+ return new HelperSet(array(new FormatterHelper()));
+ }
+}

0 comments on commit 452df2b

Please sign in to comment.
Something went wrong with that request. Please try again.