FactoryCommandLoaderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\CommandLoader;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
  14. class FactoryCommandLoaderTest extends TestCase
  15. {
  16. public function testHas()
  17. {
  18. $loader = new FactoryCommandLoader([
  19. 'foo' => function () { return new Command('foo'); },
  20. 'bar' => function () { return new Command('bar'); },
  21. ]);
  22. $this->assertTrue($loader->has('foo'));
  23. $this->assertTrue($loader->has('bar'));
  24. $this->assertFalse($loader->has('baz'));
  25. }
  26. public function testGet()
  27. {
  28. $loader = new FactoryCommandLoader([
  29. 'foo' => function () { return new Command('foo'); },
  30. 'bar' => function () { return new Command('bar'); },
  31. ]);
  32. $this->assertInstanceOf(Command::class, $loader->get('foo'));
  33. $this->assertInstanceOf(Command::class, $loader->get('bar'));
  34. }
  35. /**
  36. * @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
  37. */
  38. public function testGetUnknownCommandThrows()
  39. {
  40. (new FactoryCommandLoader([]))->get('unknown');
  41. }
  42. public function testGetCommandNames()
  43. {
  44. $loader = new FactoryCommandLoader([
  45. 'foo' => function () { return new Command('foo'); },
  46. 'bar' => function () { return new Command('bar'); },
  47. ]);
  48. $this->assertSame(['foo', 'bar'], $loader->getNames());
  49. }
  50. }