FactoryCommandLoaderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. public function testGetUnknownCommandThrows()
  36. {
  37. $this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
  38. (new FactoryCommandLoader([]))->get('unknown');
  39. }
  40. public function testGetCommandNames()
  41. {
  42. $loader = new FactoryCommandLoader([
  43. 'foo' => function () { return new Command('foo'); },
  44. 'bar' => function () { return new Command('bar'); },
  45. ]);
  46. $this->assertSame(['foo', 'bar'], $loader->getNames());
  47. }
  48. }