From e72128fa869d3ed2c6c3dbc5b5b5e0dd4ca4534d Mon Sep 17 00:00:00 2001 From: Gregor Harlan Date: Tue, 31 Mar 2015 01:38:19 +0200 Subject: [PATCH 01/11] CS: Use "self" keyword instead of class name if possible --- .../Config/Definition/Builder/ExprBuilder.php | 2 +- src/Symfony/Component/Config/Loader/FileLoader.php | 2 +- src/Symfony/Component/HttpFoundation/File/File.php | 2 +- src/Symfony/Component/Intl/Intl.php | 10 +++++----- src/Symfony/Component/PropertyAccess/PropertyPath.php | 2 +- .../Routing/Matcher/Dumper/DumperCollection.php | 4 ++-- .../Routing/Matcher/Dumper/DumperPrefixCollection.php | 2 +- .../Security/Acl/Domain/RoleSecurityIdentity.php | 2 +- .../Security/Acl/Domain/UserSecurityIdentity.php | 2 +- src/Symfony/Component/Validator/Constraint.php | 2 +- src/Symfony/Component/Yaml/Parser.php | 8 ++++---- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php index 7887f2d288..3d79b29858 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/ExprBuilder.php @@ -224,7 +224,7 @@ class ExprBuilder public static function buildExpressions(array $expressions) { foreach ($expressions as $k => $expr) { - if ($expr instanceof ExprBuilder) { + if ($expr instanceof self) { $if = $expr->ifPart; $then = $expr->thenPart; $expressions[$k] = function ($v) use ($if, $then) { diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index 21e4c47331..c1add20cea 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -82,7 +82,7 @@ abstract class FileLoader extends Loader try { $loader = $this->resolve($resource, $type); - if ($loader instanceof FileLoader && null !== $this->currentDir) { + if ($loader instanceof self && null !== $this->currentDir) { // we fallback to the current locator to keep BC // as some some loaders do not call the parent __construct() // @deprecated should be removed in 3.0 diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index dc0e2f7656..87c1606d4a 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -139,7 +139,7 @@ class File extends \SplFileInfo $target = rtrim($directory, '/\\').DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); - return new File($target, false); + return new self($target, false); } /** diff --git a/src/Symfony/Component/Intl/Intl.php b/src/Symfony/Component/Intl/Intl.php index 58a3e84809..cb14e334d0 100644 --- a/src/Symfony/Component/Intl/Intl.php +++ b/src/Symfony/Component/Intl/Intl.php @@ -117,7 +117,7 @@ final class Intl { if (null === self::$currencyBundle) { self::$currencyBundle = new CurrencyBundle( - self::getDataDirectory().'/'.Intl::CURRENCY_DIR, + self::getDataDirectory().'/'.self::CURRENCY_DIR, self::getEntryReader(), self::getLocaleBundle() ); @@ -135,11 +135,11 @@ final class Intl { if (null === self::$languageBundle) { self::$languageBundle = new LanguageBundle( - self::getDataDirectory().'/'.Intl::LANGUAGE_DIR, + self::getDataDirectory().'/'.self::LANGUAGE_DIR, self::getEntryReader(), self::getLocaleBundle(), new ScriptDataProvider( - self::getDataDirectory().'/'.Intl::SCRIPT_DIR, + self::getDataDirectory().'/'.self::SCRIPT_DIR, self::getEntryReader() ) ); @@ -157,7 +157,7 @@ final class Intl { if (null === self::$localeBundle) { self::$localeBundle = new LocaleBundle( - self::getDataDirectory().'/'.Intl::LOCALE_DIR, + self::getDataDirectory().'/'.self::LOCALE_DIR, self::getEntryReader() ); } @@ -174,7 +174,7 @@ final class Intl { if (null === self::$regionBundle) { self::$regionBundle = new RegionBundle( - self::getDataDirectory().'/'.Intl::REGION_DIR, + self::getDataDirectory().'/'.self::REGION_DIR, self::getEntryReader(), self::getLocaleBundle() ); diff --git a/src/Symfony/Component/PropertyAccess/PropertyPath.php b/src/Symfony/Component/PropertyAccess/PropertyPath.php index 109902ce69..9e44d8b752 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyPath.php +++ b/src/Symfony/Component/PropertyAccess/PropertyPath.php @@ -76,7 +76,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface public function __construct($propertyPath) { // Can be used as copy constructor - if ($propertyPath instanceof PropertyPath) { + if ($propertyPath instanceof self) { /* @var PropertyPath $propertyPath */ $this->elements = $propertyPath->elements; $this->singulars = $propertyPath->singulars; diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php b/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php index ce3a6aa86e..f91df98476 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php @@ -50,7 +50,7 @@ class DumperCollection implements \IteratorAggregate */ public function add($child) { - if ($child instanceof DumperCollection) { + if ($child instanceof self) { $child->setParent($this); } $this->children[] = $child; @@ -64,7 +64,7 @@ class DumperCollection implements \IteratorAggregate public function setAll(array $children) { foreach ($children as $child) { - if ($child instanceof DumperCollection) { + if ($child instanceof self) { $child->setParent($this); } } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php b/src/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php index c94377359f..6a615f21ad 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/DumperPrefixCollection.php @@ -66,7 +66,7 @@ class DumperPrefixCollection extends DumperCollection // Prefix starts with route's prefix if ('' === $collection->prefix || 0 === strpos($prefix, $collection->prefix)) { - $child = new DumperPrefixCollection(); + $child = new self(); $child->setPrefix(substr($prefix, 0, strlen($collection->prefix) + 1)); $collection->add($child); diff --git a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php index 5410a46b37..c28a1c522d 100644 --- a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php +++ b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php @@ -52,7 +52,7 @@ final class RoleSecurityIdentity implements SecurityIdentityInterface */ public function equals(SecurityIdentityInterface $sid) { - if (!$sid instanceof RoleSecurityIdentity) { + if (!$sid instanceof self) { return false; } diff --git a/src/Symfony/Component/Security/Acl/Domain/UserSecurityIdentity.php b/src/Symfony/Component/Security/Acl/Domain/UserSecurityIdentity.php index e3d9a34bae..3bf277f364 100644 --- a/src/Symfony/Component/Security/Acl/Domain/UserSecurityIdentity.php +++ b/src/Symfony/Component/Security/Acl/Domain/UserSecurityIdentity.php @@ -102,7 +102,7 @@ final class UserSecurityIdentity implements SecurityIdentityInterface */ public function equals(SecurityIdentityInterface $sid) { - if (!$sid instanceof UserSecurityIdentity) { + if (!$sid instanceof self) { return false; } diff --git a/src/Symfony/Component/Validator/Constraint.php b/src/Symfony/Component/Validator/Constraint.php index 0ac47fd0b5..a8dbac478d 100644 --- a/src/Symfony/Component/Validator/Constraint.php +++ b/src/Symfony/Component/Validator/Constraint.php @@ -154,7 +154,7 @@ abstract class Constraint */ public function addImplicitGroupName($group) { - if (in_array(Constraint::DEFAULT_GROUP, $this->groups) && !in_array($group, $this->groups)) { + if (in_array(self::DEFAULT_GROUP, $this->groups) && !in_array($group, $this->groups)) { $this->groups[] = $group; } } diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 9ecb206ce2..ae4f500f7d 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -91,7 +91,7 @@ class Parser // array if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) { $c = $this->getRealCurrentLineNb() + 1; - $parser = new Parser($c); + $parser = new self($c); $parser->refs = &$this->refs; $data[] = $parser->parse($this->getNextEmbedBlock(null, true), $exceptionOnInvalidType, $objectSupport); } else { @@ -100,7 +100,7 @@ class Parser ) { // this is a compact notation element, add to next block and parse $c = $this->getRealCurrentLineNb(); - $parser = new Parser($c); + $parser = new self($c); $parser->refs = &$this->refs; $block = $values['value']; @@ -143,7 +143,7 @@ class Parser $value = $this->getNextEmbedBlock(); } $c = $this->getRealCurrentLineNb() + 1; - $parser = new Parser($c); + $parser = new self($c); $parser->refs = &$this->refs; $parsed = $parser->parse($value, $exceptionOnInvalidType, $objectSupport); @@ -180,7 +180,7 @@ class Parser $data[$key] = null; } else { $c = $this->getRealCurrentLineNb() + 1; - $parser = new Parser($c); + $parser = new self($c); $parser->refs = &$this->refs; $data[$key] = $parser->parse($this->getNextEmbedBlock(), $exceptionOnInvalidType, $objectSupport); } From efc1c038669487eb2db4281083c28c9c81d105c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 2 Apr 2015 22:42:16 +0200 Subject: [PATCH 02/11] [Validator] Use strict comparisons in loaders --- .../Component/Validator/Mapping/Loader/AnnotationLoader.php | 4 ++-- .../Component/Validator/Mapping/Loader/YamlFileLoader.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php index 6e71b959bd..4703209142 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php @@ -57,7 +57,7 @@ class AnnotationLoader implements LoaderInterface } foreach ($reflClass->getProperties() as $property) { - if ($property->getDeclaringClass()->name == $className) { + if ($property->getDeclaringClass()->name === $className) { foreach ($this->reader->getPropertyAnnotations($property) as $constraint) { if ($constraint instanceof Constraint) { $metadata->addPropertyConstraint($property->name, $constraint); @@ -69,7 +69,7 @@ class AnnotationLoader implements LoaderInterface } foreach ($reflClass->getMethods() as $method) { - if ($method->getDeclaringClass()->name == $className) { + if ($method->getDeclaringClass()->name === $className) { foreach ($this->reader->getMethodAnnotations($method) as $constraint) { if ($constraint instanceof Constraint) { if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) { diff --git a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php index e293a6eb38..6075b270ba 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/YamlFileLoader.php @@ -85,7 +85,7 @@ class YamlFileLoader extends FileLoader $values = array(); foreach ($nodes as $name => $childNodes) { - if (is_numeric($name) && is_array($childNodes) && count($childNodes) == 1) { + if (is_numeric($name) && is_array($childNodes) && 1 === count($childNodes)) { $options = current($childNodes); if (is_array($options)) { From f62b050fa463ac2245c2da2cd965dd61fe5171c4 Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Sat, 4 Apr 2015 14:31:25 -0300 Subject: [PATCH 03/11] Removed useless strtolower call --- src/Symfony/Component/DependencyInjection/ContainerBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 87b6118798..0d63c0be39 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -770,7 +770,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface */ public function register($id, $class = null) { - return $this->setDefinition(strtolower($id), new Definition($class)); + return $this->setDefinition($id, new Definition($class)); } /** From 0b70d02e3f2b312bab7fd0fb1b4936e4569bfe8b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Apr 2015 13:23:11 +0200 Subject: [PATCH 04/11] Remove some useless @group annotations --- .travis.yml | 4 ++-- .../Tests/Validator/Constraints/UniqueEntityValidatorTest.php | 4 ---- .../Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php | 3 --- .../Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php | 3 --- .../Bundle/FrameworkBundle/Tests/Functional/SessionTest.php | 3 --- .../FrameworkBundle/Tests/Functional/SubRequestsTest.php | 3 --- .../SecurityBundle/Tests/Functional/CsrfFormLoginTest.php | 3 --- .../Tests/Functional/FirewallEntryPointTest.php | 3 --- .../Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php | 3 --- .../Tests/Functional/SecurityRoutingIntegrationTest.php | 2 -- .../Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php | 3 --- src/Symfony/Component/Finder/Tests/FinderTest.php | 3 --- 12 files changed, 2 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0943d93975..a949e64237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,5 +45,5 @@ install: script: - if [ "$deps" = "no" ]; then echo "$components" | parallel --gnu --keep-order 'echo -e "\\nRunning {} tests"; phpunit --exclude-group tty,benchmark,intl-data {} || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; - if [ "$deps" = "no" ]; then echo -e "\\nRunning tests requiring tty"; phpunit --group tty || (echo -e "\\e[41mKO\\e[0m tty group" && $(exit 1)); fi; - - if [ "$deps" = "high" ]; then echo "$components" | parallel --gnu --keep-order -j25% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; phpunit --exclude-group tty,benchmark,intl-data || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; - - if [ "$deps" = "low" ]; then echo "$components" | parallel --gnu --keep-order -j25% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; phpunit --exclude-group tty,benchmark,intl-data || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; + - if [ "$deps" = "high" ]; then echo "$components" | parallel --gnu --keep-order -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source update; phpunit --exclude-group tty,benchmark,intl-data || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; + - if [ "$deps" = "low" ]; then echo "$components" | parallel --gnu --keep-order -j10% 'echo -e "\\nRunning {} tests"; cd {}; composer --prefer-source --prefer-lowest --prefer-stable update; phpunit --exclude-group tty,benchmark,intl-data || (echo -e "\\e[41mKO\\e[0m {}" && $(exit 1));'; fi; diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 4fefe1d523..9c2b510d34 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -330,9 +330,6 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest $this->assertNoViolation(); } - /** - * @group GH-1635 - */ public function testAssociatedEntity() { $constraint = new UniqueEntity(array( @@ -389,7 +386,6 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException * @expectedExceptionMessage Associated entities are not allowed to have more than one identifier field - * @group GH-1635 */ public function testAssociatedCompositeEntity() { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php index eafe6bd43e..dff65d636c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FragmentTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -/** - * @group functional - */ class FragmentTest extends WebTestCase { /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php index d4eb927ff8..a8741124fd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -/** - * @group functional - */ class ProfilerTest extends WebTestCase { /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php index 3e90e9d7a0..415e031189 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -/** - * @group functional - */ class SessionTest extends WebTestCase { /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php index 2676653b1e..2aaeb220f7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -/** - * @group functional - */ class SubRequestsTest extends WebTestCase { public function testStateAfterSubRequest() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php index 4c4c1ac295..c2299c9a51 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/CsrfFormLoginTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional; -/** - * @group functional - */ class CsrfFormLoginTest extends WebTestCase { /** diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php index 656d493009..269cea3b72 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FirewallEntryPointTest.php @@ -13,9 +13,6 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional; use Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\FirewallEntryPointBundle\Security\EntryPointStub; -/** - * @group functional - */ class FirewallEntryPointTest extends WebTestCase { public function testItUsesTheConfiguredEntryPointWhenUsingUnknownCredentials() diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php index 0dc038e1df..1b8415ad2a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/FormLoginTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional; -/** - * @group functional - */ class FormLoginTest extends WebTestCase { /** diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php index 8239f99ea9..5beec6f927 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SecurityRoutingIntegrationTest.php @@ -65,7 +65,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase /** * @dataProvider getConfigs - * @group ip_whitelist */ public function testSecurityConfigurationForSingleIPAddress($config) { @@ -78,7 +77,6 @@ class SecurityRoutingIntegrationTest extends WebTestCase /** * @dataProvider getConfigs - * @group ip_whitelist */ public function testSecurityConfigurationForMultipleIPAddresses($config) { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php index d9472f2f7d..f4b3d27f21 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/SwitchUserTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional; -/** - * @group functional - */ class SwitchUserTest extends WebTestCase { /** diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 67625e9681..c5c282b234 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -132,8 +132,6 @@ class FinderTest extends Iterator\RealIteratorTestCase /** * @dataProvider getRegexNameTestData - * - * @group regexName */ public function testRegexName($adapter, $regex) { @@ -495,7 +493,6 @@ class FinderTest extends Iterator\RealIteratorTestCase /** * @dataProvider getContainsTestData - * @group grep */ public function testContains($adapter, $matchPatterns, $noMatchPatterns, $expected) { From dae19422ecfda69dcb3d41316a0c7a990da58dad Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 7 Apr 2015 13:59:04 +0200 Subject: [PATCH 05/11] [Process] Fix volatile test --- .../Process/Tests/AbstractProcessTest.php | 14 ++++---------- .../Stopwatch/Tests/StopwatchEventTest.php | 2 ++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index 2b9c36d08a..7e26976d62 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -800,9 +800,6 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->assertFalse($process->isSuccessful()); } - /** - * @group idle-timeout - */ public function testIdleTimeout() { $process = $this->getProcess('php -r "sleep(3);"'); @@ -820,21 +817,18 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase } } - /** - * @group idle-timeout - */ public function testIdleTimeoutNotExceededWhenOutputIsSent() { - $process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'foo\'; sleep(1); echo \'foo\'; sleep(1); "'); + $process = $this->getProcess(sprintf('php -r %s', escapeshellarg('$n = 30; while ($n--) {echo "foo\n"; usleep(100000); }'))); $process->setTimeout(2); - $process->setIdleTimeout(1.5); + $process->setIdleTimeout(1); try { $process->run(); $this->fail('A timeout exception was expected.'); } catch (ProcessTimedOutException $ex) { - $this->assertTrue($ex->isGeneralTimeout()); - $this->assertFalse($ex->isIdleTimeout()); + $this->assertTrue($ex->isGeneralTimeout(), 'A general timeout is expected.'); + $this->assertFalse($ex->isIdleTimeout(), 'No idle timeout is expected.'); $this->assertEquals(2, $ex->getExceededTimeout()); } } diff --git a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php index 7ff2942991..ff4519686f 100644 --- a/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php +++ b/src/Symfony/Component/Stopwatch/Tests/StopwatchEventTest.php @@ -76,6 +76,7 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase $event->start(); usleep(100000); $event->stop(); + usleep(50000); $event->start(); usleep(100000); $event->stop(); @@ -93,6 +94,7 @@ class StopwatchEventTest extends \PHPUnit_Framework_TestCase $event->start(); usleep(100000); $event->stop(); + usleep(50000); $event->start(); usleep(100000); $this->assertEquals(100, $event->getDuration(), null, self::DELTA); From 39109404da9dc4f8a2fccf6fc67725760d9c4e98 Mon Sep 17 00:00:00 2001 From: WouterJ Date: Sat, 3 Jan 2015 14:42:01 +0100 Subject: [PATCH 06/11] [Console] Made output docopt compatible --- .../Component/Console/Command/Command.php | 44 +++++- .../Console/Descriptor/JsonDescriptor.php | 7 +- .../Console/Descriptor/MarkdownDescriptor.php | 12 +- .../Console/Descriptor/TextDescriptor.php | 137 +++++++++++------- .../Console/Descriptor/XmlDescriptor.php | 13 +- .../Console/Input/InputDefinition.php | 40 ++++- .../Console/Tests/Command/CommandTest.php | 4 +- .../Console/Tests/Command/HelpCommandTest.php | 22 ++- .../Console/Tests/Command/ListCommandTest.php | 2 +- .../Descriptor/AbstractDescriptorTest.php | 2 +- .../Tests/Descriptor/JsonDescriptorTest.php | 8 + .../Tests/Descriptor/ObjectsProvider.php | 2 + .../Tests/Fixtures/DescriptorCommand2.php | 2 + .../Console/Tests/Fixtures/application_1.json | 2 +- .../Console/Tests/Fixtures/application_1.md | 10 +- .../Console/Tests/Fixtures/application_1.txt | 20 +-- .../Console/Tests/Fixtures/application_1.xml | 10 +- .../Console/Tests/Fixtures/application_2.json | 2 +- .../Console/Tests/Fixtures/application_2.md | 24 ++- .../Console/Tests/Fixtures/application_2.txt | 30 ++-- .../Console/Tests/Fixtures/application_2.xml | 27 ++-- .../Tests/Fixtures/application_astext1.txt | 26 ++-- .../Tests/Fixtures/application_astext2.txt | 18 +-- .../Tests/Fixtures/application_asxml1.txt | 18 ++- .../Tests/Fixtures/application_asxml2.txt | 8 +- .../Fixtures/application_renderexception2.txt | 2 +- .../Tests/Fixtures/application_run1.txt | 20 +-- .../Tests/Fixtures/application_run2.txt | 26 ++-- .../Tests/Fixtures/application_run3.txt | 10 +- .../Console/Tests/Fixtures/command_1.json | 2 +- .../Console/Tests/Fixtures/command_1.md | 7 +- .../Console/Tests/Fixtures/command_1.txt | 6 +- .../Console/Tests/Fixtures/command_1.xml | 10 +- .../Console/Tests/Fixtures/command_2.json | 2 +- .../Console/Tests/Fixtures/command_2.md | 7 +- .../Console/Tests/Fixtures/command_2.txt | 8 +- .../Console/Tests/Fixtures/command_2.xml | 7 +- .../Console/Tests/Fixtures/command_astext.txt | 20 +-- .../Console/Tests/Fixtures/command_asxml.txt | 8 +- .../Tests/Fixtures/definition_astext.txt | 16 +- .../Tests/Fixtures/input_argument_1.txt | 2 +- .../Tests/Fixtures/input_argument_2.txt | 2 +- .../Tests/Fixtures/input_argument_3.txt | 2 +- .../Tests/Fixtures/input_argument_4.json | 1 + .../Tests/Fixtures/input_argument_4.md | 8 + .../Tests/Fixtures/input_argument_4.txt | 2 + .../Tests/Fixtures/input_argument_4.xml | 6 + .../Tests/Fixtures/input_definition_2.txt | 2 +- .../Tests/Fixtures/input_definition_3.txt | 2 +- .../Tests/Fixtures/input_definition_4.txt | 4 +- .../Console/Tests/Fixtures/input_option_1.txt | 2 +- .../Console/Tests/Fixtures/input_option_2.txt | 2 +- .../Console/Tests/Fixtures/input_option_3.txt | 2 +- .../Console/Tests/Fixtures/input_option_4.txt | 2 +- .../Tests/Fixtures/input_option_5.json | 1 + .../Console/Tests/Fixtures/input_option_5.md | 10 ++ .../Console/Tests/Fixtures/input_option_5.txt | 2 + .../Console/Tests/Fixtures/input_option_5.xml | 6 + .../Tests/Input/InputDefinitionTest.php | 45 +++--- .../DomCrawler/Tests/CrawlerTest.php | 7 + 60 files changed, 469 insertions(+), 282 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_5.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_5.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_5.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/input_option_5.xml diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index b70692fc6a..fdfe8a34fa 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -42,7 +42,8 @@ class Command private $applicationDefinitionMerged = false; private $applicationDefinitionMergedWithArgs = false; private $code; - private $synopsis; + private $synopsis = array(); + private $usages = array(); private $helperSet; /** @@ -215,7 +216,8 @@ class Command public function run(InputInterface $input, OutputInterface $output) { // force the creation of the synopsis before the merge with the app definition - $this->getSynopsis(); + $this->getSynopsis(true); + $this->getSynopsis(false); // add the application arguments and options $this->mergeApplicationDefinition(); @@ -573,15 +575,45 @@ class Command /** * Returns the synopsis for the command. * + * @param bool $short Whether to show the short version of the synopsis (with options folded) or not + * * @return string The synopsis */ - public function getSynopsis() + public function getSynopsis($short = false) { - if (null === $this->synopsis) { - $this->synopsis = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis())); + $key = $short ? 'short' : 'long'; + + if (!isset($this->synopsis[$key])) { + $this->synopsis[$key] = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis($short))); } - return $this->synopsis; + return $this->synopsis[$key]; + } + + /** + * Add a command usage example. + * + * @param string $usage The usage, it'll be prefixed with the command name + */ + public function addUsage($usage) + { + if (0 !== strpos($usage, $this->name)) { + $usage = sprintf('%s %s', $this->name, $usage); + } + + $this->usages[] = $usage; + + return $this; + } + + /** + * Returns alternative usages of the command. + * + * @return array + */ + public function getUsages() + { + return $this->usages; } /** diff --git a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php index 13785a40fe..8649d3ac45 100644 --- a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php @@ -102,7 +102,7 @@ class JsonDescriptor extends Descriptor 'name' => $argument->getName(), 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), - 'description' => $argument->getDescription(), + 'description' => preg_replace('/\s*\R\s*/', ' ', $argument->getDescription()), 'default' => $argument->getDefault(), ); } @@ -120,7 +120,7 @@ class JsonDescriptor extends Descriptor 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), - 'description' => $option->getDescription(), + 'description' => preg_replace('/\s*\R\s*/', ' ', $option->getDescription()), 'default' => $option->getDefault(), ); } @@ -157,10 +157,9 @@ class JsonDescriptor extends Descriptor return array( 'name' => $command->getName(), - 'usage' => $command->getSynopsis(), + 'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()), 'description' => $command->getDescription(), 'help' => $command->getProcessedHelp(), - 'aliases' => $command->getAliases(), 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()), ); } diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 78d48b9508..10f05168d4 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -36,7 +36,7 @@ class MarkdownDescriptor extends Descriptor .'* Name: '.($argument->getName() ?: '')."\n" .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n" .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n" - .'* Description: '.($argument->getDescription() ?: '')."\n" + .'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $argument->getDescription() ?: '')."\n" .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`' ); } @@ -53,7 +53,7 @@ class MarkdownDescriptor extends Descriptor .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n" .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n" .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n" - .'* Description: '.($option->getDescription() ?: '')."\n" + .'* Description: '.preg_replace('/\s*\R\s*/', PHP_EOL.' ', $option->getDescription() ?: '')."\n" .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`' ); } @@ -96,12 +96,14 @@ class MarkdownDescriptor extends Descriptor $command->getName()."\n" .str_repeat('-', strlen($command->getName()))."\n\n" .'* Description: '.($command->getDescription() ?: '')."\n" - .'* Usage: `'.$command->getSynopsis().'`'."\n" - .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : '') + .'* Usage:'."\n\n" + .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { + return $carry .= ' * `'.$usage.'`'."\n"; + }) ); if ($help = $command->getProcessedHelp()) { - $this->write("\n\n"); + $this->write("\n"); $this->write($help); } diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index 0b3dd5a41d..37bae0663e 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -32,16 +32,19 @@ class TextDescriptor extends Descriptor protected function describeInputArgument(InputArgument $argument, array $options = array()) { if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) { - $default = sprintf(' (default: %s)', $this->formatDefaultValue($argument->getDefault())); + $default = sprintf(' [default: %s]', $this->formatDefaultValue($argument->getDefault())); } else { $default = ''; } - $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName()); + $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName()); + $spacingWidth = $totalWidth - strlen($argument->getName()) + 2; - $this->writeText(sprintf(" %-${nameWidth}s %s%s", + $this->writeText(sprintf(" %s%s%s%s", $argument->getName(), - str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()), + str_repeat(' ', $spacingWidth), + // + 17 = 2 spaces + + + 2 spaces + preg_replace('/\s*\R\s*/', PHP_EOL.str_repeat(' ', $totalWidth + 17), $argument->getDescription()), $default ), $options); } @@ -52,18 +55,33 @@ class TextDescriptor extends Descriptor protected function describeInputOption(InputOption $option, array $options = array()) { if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) { - $default = sprintf(' (default: %s)', $this->formatDefaultValue($option->getDefault())); + $default = sprintf(' [default: %s]', $this->formatDefaultValue($option->getDefault())); } else { $default = ''; } - $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName()); - $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2; + $value = ''; + if ($option->acceptValue()) { + $value = '='.strtoupper($option->getName()); - $this->writeText(sprintf(" %s %-${nameWithShortcutWidth}s%s%s%s", - '--'.$option->getName(), - $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', - str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()), + if ($option->isValueOptional()) { + $value = '['.$value.']'; + } + } + + $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option)); + $synopsis = sprintf('%s%s', + $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ', + sprintf('--%s%s', $option->getName(), $value) + ); + + $spacingWidth = $totalWidth - strlen($synopsis) + 2; + + $this->writeText(sprintf(" %s%s%s%s%s", + $synopsis, + str_repeat(' ', $spacingWidth), + // + 17 = 2 spaces + + + 2 spaces + preg_replace('/\s*\R\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()), $default, $option->isArray() ? ' (multiple values allowed)' : '' ), $options); @@ -74,24 +92,16 @@ class TextDescriptor extends Descriptor */ protected function describeInputDefinition(InputDefinition $definition, array $options = array()) { - $nameWidth = 0; - foreach ($definition->getOptions() as $option) { - $nameLength = strlen($option->getName()) + 2; - if ($option->getShortcut()) { - $nameLength += strlen($option->getShortcut()) + 3; - } - $nameWidth = max($nameWidth, $nameLength); - } + $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); foreach ($definition->getArguments() as $argument) { - $nameWidth = max($nameWidth, strlen($argument->getName())); + $totalWidth = max($totalWidth, strlen($argument->getName())); } - ++$nameWidth; if ($definition->getArguments()) { $this->writeText('Arguments:', $options); $this->writeText("\n"); foreach ($definition->getArguments() as $argument) { - $this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth))); + $this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth))); $this->writeText("\n"); } } @@ -101,11 +111,20 @@ class TextDescriptor extends Descriptor } if ($definition->getOptions()) { + $laterOptions = array(); + $this->writeText('Options:', $options); - $this->writeText("\n"); foreach ($definition->getOptions() as $option) { - $this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth))); + if (strlen($option->getShortcut()) > 1) { + $laterOptions[] = $option; + continue; + } $this->writeText("\n"); + $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth))); + } + foreach ($laterOptions as $option) { + $this->writeText("\n"); + $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth))); } } } @@ -115,27 +134,26 @@ class TextDescriptor extends Descriptor */ protected function describeCommand(Command $command, array $options = array()) { - $command->getSynopsis(); + $command->getSynopsis(true); + $command->getSynopsis(false); $command->mergeApplicationDefinition(false); $this->writeText('Usage:', $options); - $this->writeText("\n"); - $this->writeText(' '.$command->getSynopsis(), $options); - $this->writeText("\n"); - - if (count($command->getAliases()) > 0) { + foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) { $this->writeText("\n"); - $this->writeText('Aliases: '.implode(', ', $command->getAliases()).'', $options); + $this->writeText(' '.$usage, $options); } + $this->writeText("\n"); - if ($definition = $command->getNativeDefinition()) { + $definition = $command->getNativeDefinition(); + if ($definition->getOptions() || $definition->getArguments()) { $this->writeText("\n"); $this->describeInputDefinition($definition, $options); + $this->writeText("\n"); } - $this->writeText("\n"); - if ($help = $command->getProcessedHelp()) { + $this->writeText("\n"); $this->writeText('Help:', $options); $this->writeText("\n"); $this->writeText(' '.str_replace("\n", "\n ", $help), $options); @@ -164,27 +182,12 @@ class TextDescriptor extends Descriptor } $this->writeText("Usage:\n", $options); - $this->writeText(" command [options] [arguments]\n\n", $options); - $this->writeText('Options:', $options); + $this->writeText(" command [options] [arguments]\n\n", $options); - $inputOptions = $application->getDefinition()->getOptions(); + $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options); - $width = 0; - foreach ($inputOptions as $option) { - $nameLength = strlen($option->getName()) + 2; - if ($option->getShortcut()) { - $nameLength += strlen($option->getShortcut()) + 3; - } - $width = max($width, $nameLength); - } - ++$width; - - foreach ($inputOptions as $option) { - $this->writeText("\n", $options); - $this->describeInputOption($option, array_merge($options, array('name_width' => $width))); - } - - $this->writeText("\n\n", $options); + $this->writeText("\n"); + $this->writeText("\n"); $width = $this->getColumnWidth($description->getCommands()); @@ -198,12 +201,13 @@ class TextDescriptor extends Descriptor foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); - $this->writeText(''.$namespace['id'].'', $options); + $this->writeText(' '.$namespace['id'].'', $options); } foreach ($namespace['commands'] as $name) { $this->writeText("\n"); - $this->writeText(sprintf(" %-${width}s %s", $name, $description->getCommand($name)->getDescription()), $options); + $spacingWidth = $width - strlen($name); + $this->writeText(sprintf(" %s%s%s", $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); } } @@ -252,4 +256,27 @@ class TextDescriptor extends Descriptor return $width + 2; } + + /** + * @param InputOption[] $options + * + * @return int + */ + private function calculateTotalWidthForOptions($options) + { + $totalWidth = 0; + foreach ($options as $option) { + $nameLength = 4 + strlen($option->getName()) + 2; // - + shortcut + , + whitespace + name + -- + + if ($option->acceptValue()) { + $valueLength = 1 + strlen($option->getName()); // = + value + $valueLength += $option->isValueOptional() ? 2 : 0; // [ + ] + + $nameLength += $valueLength; + } + $totalWidth = max($totalWidth, $nameLength); + } + + return $totalWidth; + } } diff --git a/src/Symfony/Component/Console/Descriptor/XmlDescriptor.php b/src/Symfony/Component/Console/Descriptor/XmlDescriptor.php index 5054686697..b5676beb37 100644 --- a/src/Symfony/Component/Console/Descriptor/XmlDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/XmlDescriptor.php @@ -65,8 +65,11 @@ class XmlDescriptor extends Descriptor $commandXML->setAttribute('id', $command->getName()); $commandXML->setAttribute('name', $command->getName()); - $commandXML->appendChild($usageXML = $dom->createElement('usage')); - $usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), ''))); + $commandXML->appendChild($usagesXML = $dom->createElement('usages')); + + foreach (array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()) as $usage) { + $usagesXML->appendChild($dom->createElement('usage', $usage)); + } $commandXML->appendChild($descriptionXML = $dom->createElement('description')); $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription()))); @@ -74,12 +77,6 @@ class XmlDescriptor extends Descriptor $commandXML->appendChild($helpXML = $dom->createElement('help')); $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp()))); - $commandXML->appendChild($aliasesXML = $dom->createElement('aliases')); - foreach ($command->getAliases() as $alias) { - $aliasesXML->appendChild($aliasXML = $dom->createElement('alias')); - $aliasXML->appendChild($dom->createTextNode($alias)); - } - $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition()); $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0)); diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php index 51d1bdd8aa..7efb849ab2 100644 --- a/src/Symfony/Component/Console/Input/InputDefinition.php +++ b/src/Symfony/Component/Console/Input/InputDefinition.php @@ -391,22 +391,50 @@ class InputDefinition /** * Gets the synopsis. * + * @param bool $short Whether to return the short version (with options foloded) or not + * * @return string The synopsis */ - public function getSynopsis() + public function getSynopsis($short = false) { $elements = array(); - foreach ($this->getOptions() as $option) { - $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : ''; - $elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName()); + + if ($short && $this->getOptions()) { + $elements[] = '[options]'; + } elseif (!$short) { + foreach ($this->getOptions() as $option) { + $value = ''; + if ($option->acceptValue()) { + $value = sprintf( + ' %s%s%s', + $option->isValueOptional() ? '[' : '', + strtoupper($option->getName()), + $option->isValueOptional() ? ']' : '' + ); + } + + $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : ''; + $elements[] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value); + } + } + + if (count($elements) && $this->getArguments()) { + $elements[] = '[--]'; } foreach ($this->getArguments() as $argument) { - $elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : '')); + $element = '<'.$argument->getName().'>'; + if (!$argument->isRequired()) { + $element = '['.$element.']'; + } elseif ($argument->isArray()) { + $element = $element.' ('.$element.')'; + } if ($argument->isArray()) { - $elements[] = sprintf('... [%sN]', $argument->getName()); + $element .= '...'; } + + $elements[] = $element; } return implode(' ', $elements); diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index 36c14ddec5..b11a00a4ab 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -154,8 +154,8 @@ class CommandTest extends \PHPUnit_Framework_TestCase { $command = new \TestCommand(); $command->addOption('foo'); - $command->addArgument('foo'); - $this->assertEquals('namespace:name [--foo] [foo]', $command->getSynopsis(), '->getSynopsis() returns the synopsis'); + $command->addArgument('bar'); + $this->assertEquals('namespace:name [--foo] [--] []', $command->getSynopsis(), '->getSynopsis() returns the synopsis'); } public function testGetHelper() diff --git a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php index ea69c8ba3b..9e068587f8 100644 --- a/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php @@ -23,8 +23,10 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $command = new HelpCommand(); $command->setApplication(new Application()); $commandTester = new CommandTester($command); - $commandTester->execute(array('command_name' => 'li')); - $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); + $commandTester->execute(array('command_name' => 'li'), array('decorated' => false)); + $this->assertContains('list [options] [--] []', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); + $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); + $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias'); } public function testExecuteForCommand() @@ -32,8 +34,10 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $command = new HelpCommand(); $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); - $commandTester->execute(array()); - $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $commandTester->execute(array(), array('decorated' => false)); + $this->assertContains('list [options] [--] []', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForCommandWithXmlOption() @@ -42,7 +46,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $commandTester = new CommandTester($command); $command->setCommand(new ListCommand()); $commandTester->execute(array('--format' => 'xml')); - $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --xml is passed'); + $this->assertContains('getDisplay(), '->execute() returns an XML help text if --xml is passed'); } public function testExecuteForApplicationCommand() @@ -50,7 +54,9 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list')); - $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('list [options] [--] []', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); } public function testExecuteForApplicationCommandWithXmlOption() @@ -58,7 +64,7 @@ class HelpCommandTest extends \PHPUnit_Framework_TestCase $application = new Application(); $commandTester = new CommandTester($application->get('help')); $commandTester->execute(array('command_name' => 'list', '--format' => 'xml')); - $this->assertRegExp('/list \[--xml\] \[--raw\] \[--format="\.\.\."\] \[namespace\]/', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); - $this->assertRegExp('/getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); + $this->assertContains('list [--xml] [--raw] [--format FORMAT] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command'); + $this->assertContains('getDisplay(), '->execute() returns an XML help text if --format=xml is passed'); } } diff --git a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php index fbb9feeb68..3578d48856 100644 --- a/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/ListCommandTest.php @@ -22,7 +22,7 @@ class ListCommandTest extends \PHPUnit_Framework_TestCase $commandTester = new CommandTester($command = $application->get('list')); $commandTester->execute(array('command' => $command->getName()), array('decorated' => false)); - $this->assertRegExp('/help Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands'); + $this->assertRegExp('/help\s{2,}Displays help for a command/', $commandTester->getDisplay(), '->execute() returns a list of available commands'); } public function testExecuteListsCommandsWithXmlOption() diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index 406c6599ba..f582e7f5ad 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -96,7 +96,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase return $data; } - private function assertDescription($expectedDescription, $describedObject) + protected function assertDescription($expectedDescription, $describedObject) { $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true); $this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true)); diff --git a/src/Symfony/Component/Console/Tests/Descriptor/JsonDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/JsonDescriptorTest.php index 943ea2956a..f9a15612b3 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/JsonDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/JsonDescriptorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\JsonDescriptor; +use Symfony\Component\Console\Output\BufferedOutput; class JsonDescriptorTest extends AbstractDescriptorTest { @@ -24,4 +25,11 @@ class JsonDescriptorTest extends AbstractDescriptorTest { return 'json'; } + + protected function assertDescription($expectedDescription, $describedObject) + { + $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true); + $this->getDescriptor()->describe($output, $describedObject, array('raw_output' => true)); + $this->assertEquals(json_decode(trim($expectedDescription), true), json_decode(trim(str_replace(PHP_EOL, "\n", $output->fetch())), true)); + } } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php index a3c49d74fe..1f40d2e6a0 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php @@ -30,6 +30,7 @@ class ObjectsProvider 'input_argument_1' => new InputArgument('argument_name', InputArgument::REQUIRED), 'input_argument_2' => new InputArgument('argument_name', InputArgument::IS_ARRAY, 'argument description'), 'input_argument_3' => new InputArgument('argument_name', InputArgument::OPTIONAL, 'argument description', 'default_value'), + 'input_argument_4' => new InputArgument('argument_name', InputArgument::REQUIRED, "multiline\nargument description"), ); } @@ -40,6 +41,7 @@ class ObjectsProvider 'input_option_2' => new InputOption('option_name', 'o', InputOption::VALUE_OPTIONAL, 'option description', 'default_value'), 'input_option_3' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, 'option description'), 'input_option_4' => new InputOption('option_name', 'o', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'option description', array()), + 'input_option_5' => new InputOption('option_name', 'o', InputOption::VALUE_REQUIRED, "multiline\noption description"), ); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php index bc04ca9141..51106b9611 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommand2.php @@ -23,6 +23,8 @@ class DescriptorCommand2 extends Command ->setName('descriptor:command2') ->setDescription('command 2 description') ->setHelp('command 2 help') + ->addUsage('-o|--option_name ') + ->addUsage('') ->addArgument('argument_name', InputArgument::REQUIRED) ->addOption('option_name', 'o', InputOption::VALUE_NONE) ; diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json index 7f8d92eefc..aa4ae9a0dc 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} +{"commands":[{"name":"help","usage":["help [--xml] [--format FORMAT] [--raw] [--] []"],"description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"list","usage":["list [--xml] [--raw] [--format FORMAT] [--] []"],"description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}}],"namespaces":[{"id":"_global","commands":["help","list"]}]} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index e3804162df..c389061389 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -8,8 +8,9 @@ help ---- * Description: Displays help for a command -* Usage: `help [--xml] [--format="..."] [--raw] [command_name]` -* Aliases: +* Usage: + + * `help [--xml] [--format FORMAT] [--raw] [--] []` The help command displays help for a given command: @@ -137,8 +138,9 @@ list ---- * Description: Lists commands -* Usage: `list [--xml] [--raw] [--format="..."] [namespace]` -* Aliases: +* Usage: + + * `list [--xml] [--raw] [--format FORMAT] [--] []` The list command lists all commands: diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt index f3a1968eff..c4cf8f2164 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.txt @@ -1,17 +1,17 @@ Console Tool Usage: - command [options] [arguments] + command [options] [arguments] Options: - --help (-h) Display this help message - --quiet (-q) Do not output any message - --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - --version (-V) Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - --no-interaction (-n) Do not ask any interactive question + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: - help Displays help for a command - list Lists commands + help Displays help for a command + list Lists commands diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml index 176310886f..ed84905a06 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.xml @@ -2,7 +2,9 @@ - help [--xml] [--format="..."] [--raw] [command_name] + + help [--xml] [--format FORMAT] [--raw] [--] [<command_name>] + Displays help for a command The <info>help</info> command displays help for a given command: @@ -13,7 +15,6 @@ <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. - The command name @@ -59,7 +60,9 @@ - list [--xml] [--raw] [--format="..."] [namespace] + + list [--xml] [--raw] [--format FORMAT] [--] [<namespace>] + Lists commands The <info>list</info> command lists all commands: @@ -76,7 +79,6 @@ It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> - The namespace name diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json index 1655d47e62..241d4813b9 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.json +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.json @@ -1 +1 @@ -{"commands":[{"name":"help","usage":"help [--xml] [--format=\"...\"] [--raw] [command_name]","description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","aliases":[],"definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"list","usage":"list [--xml] [--raw] [--format=\"...\"] [namespace]","description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","aliases":[],"definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}},{"name":"descriptor:command1","usage":"descriptor:command1","description":"command 1 description","help":"command 1 help","aliases":["alias1","alias2"],"definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"descriptor:command2","usage":"descriptor:command2 [-o|--option_name] argument_name","description":"command 2 description","help":"command 2 help","aliases":[],"definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} +{"commands":[{"name":"help","usage":["help [--xml] [--format FORMAT] [--raw] [--] []"],"description":"Displays help for a command","help":"The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.","definition":{"arguments":{"command_name":{"name":"command_name","is_required":false,"is_array":false,"description":"The command name","default":"help"}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output help as XML","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output help in other formats","default":"txt"},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command help","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"list","usage":["list [--xml] [--raw] [--format FORMAT] [--] []"],"description":"Lists commands","help":"The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>","definition":{"arguments":{"namespace":{"name":"namespace","is_required":false,"is_array":false,"description":"The namespace name","default":null}},"options":{"xml":{"name":"--xml","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output list as XML","default":false},"raw":{"name":"--raw","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"To output raw command list","default":false},"format":{"name":"--format","shortcut":"","accept_value":true,"is_value_required":true,"is_multiple":false,"description":"To output list in other formats","default":"txt"}}}},{"name":"descriptor:command1","usage":["descriptor:command1", "alias1", "alias2"],"description":"command 1 description","help":"command 1 help","definition":{"arguments":[],"options":{"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}},{"name":"descriptor:command2","usage":["descriptor:command2 [-o|--option_name] [--] ", "descriptor:command2 -o|--option_name ", "descriptor:command2 "],"description":"command 2 description","help":"command 2 help","definition":{"arguments":{"argument_name":{"name":"argument_name","is_required":true,"is_array":false,"description":"","default":null}},"options":{"option_name":{"name":"--option_name","shortcut":"-o","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"","default":false},"help":{"name":"--help","shortcut":"-h","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this help message","default":false},"quiet":{"name":"--quiet","shortcut":"-q","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not output any message","default":false},"verbose":{"name":"--verbose","shortcut":"-v|-vv|-vvv","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug","default":false},"version":{"name":"--version","shortcut":"-V","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Display this application version","default":false},"ansi":{"name":"--ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Force ANSI output","default":false},"no-ansi":{"name":"--no-ansi","shortcut":"","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Disable ANSI output","default":false},"no-interaction":{"name":"--no-interaction","shortcut":"-n","accept_value":false,"is_value_required":false,"is_multiple":false,"description":"Do not ask any interactive question","default":false}}}}],"namespaces":[{"id":"_global","commands":["alias1","alias2","help","list"]},{"id":"descriptor","commands":["descriptor:command1","descriptor:command2"]}]} \ No newline at end of file diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 7492886ea3..8e0bfd3502 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -15,8 +15,9 @@ help ---- * Description: Displays help for a command -* Usage: `help [--xml] [--format="..."] [--raw] [command_name]` -* Aliases: +* Usage: + + * `help [--xml] [--format FORMAT] [--raw] [--] []` The help command displays help for a given command: @@ -144,8 +145,9 @@ list ---- * Description: Lists commands -* Usage: `list [--xml] [--raw] [--format="..."] [namespace]` -* Aliases: +* Usage: + + * `list [--xml] [--raw] [--format FORMAT] [--] []` The list command lists all commands: @@ -209,8 +211,11 @@ descriptor:command1 ------------------- * Description: command 1 description -* Usage: `descriptor:command1` -* Aliases: `alias1`, `alias2` +* Usage: + + * `descriptor:command1` + * `alias1` + * `alias2` command 1 help @@ -290,8 +295,11 @@ descriptor:command2 ------------------- * Description: command 2 description -* Usage: `descriptor:command2 [-o|--option_name] argument_name` -* Aliases: +* Usage: + + * `descriptor:command2 [-o|--option_name] [--] ` + * `descriptor:command2 -o|--option_name ` + * `descriptor:command2 ` command 2 help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt index a640a8d2d2..292aa829d8 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.txt @@ -1,22 +1,22 @@ My Symfony application version v1.0 Usage: - command [options] [arguments] + command [options] [arguments] Options: - --help (-h) Display this help message - --quiet (-q) Do not output any message - --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - --version (-V) Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - --no-interaction (-n) Do not ask any interactive question + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: - alias1 command 1 description - alias2 command 1 description - help Displays help for a command - list Lists commands -descriptor - descriptor:command1 command 1 description - descriptor:command2 command 2 description + alias1 command 1 description + alias2 command 1 description + help Displays help for a command + list Lists commands + descriptor + descriptor:command1 command 1 description + descriptor:command2 command 2 description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml index a7d65b4f86..18e5db1f64 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.xml @@ -2,7 +2,9 @@ - help [--xml] [--format="..."] [--raw] [command_name] + + help [--xml] [--format FORMAT] [--raw] [--] [<command_name>] + Displays help for a command The <info>help</info> command displays help for a given command: @@ -13,7 +15,6 @@ <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. - The command name @@ -59,7 +60,9 @@ - list [--xml] [--raw] [--format="..."] [namespace] + + list [--xml] [--raw] [--format FORMAT] [--] [<namespace>] + Lists commands The <info>list</info> command lists all commands: @@ -76,7 +79,6 @@ It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> - The namespace name @@ -99,13 +101,13 @@ - descriptor:command1 + + descriptor:command1 + alias1 + alias2 + command 1 description command 1 help - - alias1 - alias2 - - descriptor:command2 [-o|--option_name] argument_name + + descriptor:command2 [-o|--option_name] [--] <argument_name> + descriptor:command2 -o|--option_name <argument_name> + descriptor:command2 <argument_name> + command 2 description command 2 help - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt index d9734fe30a..19dacb23bf 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_astext1.txt @@ -1,20 +1,20 @@ Console Tool Usage: - command [options] [arguments] + command [options] [arguments] Options: - --help (-h) Display this help message - --quiet (-q) Do not output any message - --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - --version (-V) Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - --no-interaction (-n) Do not ask any interactive question + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: - afoobar The foo:bar command - help Displays help for a command - list Lists commands -foo - foo:bar The foo:bar command + afoobar The foo:bar command + help Displays help for a command + list Lists commands + foo + foo:bar The foo:bar command diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt index 49992cfe3b..c99ccdda7a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_astext2.txt @@ -1,16 +1,16 @@ Console Tool Usage: - command [options] [arguments] + command [options] [arguments] Options: - --help (-h) Display this help message - --quiet (-q) Do not output any message - --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug - --version (-V) Display this application version - --ansi Force ANSI output - --no-ansi Disable ANSI output - --no-interaction (-n) Do not ask any interactive question + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands for the "foo" namespace: - foo:bar The foo:bar command + foo:bar The foo:bar command diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt index d9567819a1..edc9d3f894 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_asxml1.txt @@ -2,7 +2,9 @@ - help [--xml] [--format="..."] [--raw] [command_name] + + help [--xml] [--format FORMAT] [--raw] [--] [<command_name>] + Displays help for a command The <info>help</info> command displays help for a given command: @@ -13,7 +15,6 @@ <info>php app/console help --format=xml list</info> To display the list of available commands, please use the <info>list</info> command. - The command name @@ -59,7 +60,9 @@ - list [--xml] [--raw] [--format="..."] [namespace] + + list [--xml] [--raw] [--format FORMAT] [--] [<namespace>] + Lists commands The <info>list</info> command lists all commands: @@ -76,7 +79,6 @@ It's also possible to get raw list of commands (useful for embedding command runner): <info>php app/console list --raw</info> - The namespace name @@ -99,12 +101,12 @@ - foo:bar + + foo:bar + afoobar + The foo:bar command - - afoobar -