4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Console\Tests\CommandLoader;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
17 use Symfony\Component\DependencyInjection\ServiceLocator;
19 class ContainerCommandLoaderTest extends TestCase
21 public function testHas()
23 $loader = new ContainerCommandLoader(new ServiceLocator(array(
24 'foo-service' => function () { return new Command('foo'); },
25 'bar-service' => function () { return new Command('bar'); },
26 )), array('foo' => 'foo-service', 'bar' => 'bar-service'));
28 $this->assertTrue($loader->has('foo'));
29 $this->assertTrue($loader->has('bar'));
30 $this->assertFalse($loader->has('baz'));
33 public function testGet()
35 $loader = new ContainerCommandLoader(new ServiceLocator(array(
36 'foo-service' => function () { return new Command('foo'); },
37 'bar-service' => function () { return new Command('bar'); },
38 )), array('foo' => 'foo-service', 'bar' => 'bar-service'));
40 $this->assertInstanceOf(Command::class, $loader->get('foo'));
41 $this->assertInstanceOf(Command::class, $loader->get('bar'));
45 * @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
47 public function testGetUnknownCommandThrows()
49 (new ContainerCommandLoader(new ServiceLocator(array()), array()))->get('unknown');
52 public function testGetCommandNames()
54 $loader = new ContainerCommandLoader(new ServiceLocator(array(
55 'foo-service' => function () { return new Command('foo'); },
56 'bar-service' => function () { return new Command('bar'); },
57 )), array('foo' => 'foo-service', 'bar' => 'bar-service'));
59 $this->assertSame(array('foo', 'bar'), $loader->getNames());