ApplicationDescriptionTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Console\Tests\Descriptor;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Application;
  13. use Symfony\Component\Console\Command\Command;
  14. use Symfony\Component\Console\Descriptor\ApplicationDescription;
  15. final class ApplicationDescriptionTest extends TestCase
  16. {
  17. /**
  18. * @dataProvider getNamespacesProvider
  19. */
  20. public function testGetNamespaces(array $expected, array $names)
  21. {
  22. $application = new TestApplication();
  23. foreach ($names as $name) {
  24. $application->add(new Command($name));
  25. }
  26. $this->assertSame($expected, array_keys((new ApplicationDescription($application))->getNamespaces()));
  27. }
  28. public static function getNamespacesProvider()
  29. {
  30. return [
  31. [['_global'], ['foobar']],
  32. [['a', 'b'], ['b:foo', 'a:foo', 'b:bar']],
  33. [['_global', 22, 33, 'b', 'z'], ['z:foo', '1', '33:foo', 'b:foo', '22:foo:bar']],
  34. ];
  35. }
  36. }
  37. final class TestApplication extends Application
  38. {
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function getDefaultCommands(): array
  43. {
  44. return [];
  45. }
  46. }