78eefd24f1b3ddd921c94ca7144fc0457bacaf52
[yaffs-website] / vendor / symfony / console / Tests / CommandLoader / ContainerCommandLoaderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Console\Tests\CommandLoader;
13
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;
18
19 class ContainerCommandLoaderTest extends TestCase
20 {
21     public function testHas()
22     {
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'));
27
28         $this->assertTrue($loader->has('foo'));
29         $this->assertTrue($loader->has('bar'));
30         $this->assertFalse($loader->has('baz'));
31     }
32
33     public function testGet()
34     {
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'));
39
40         $this->assertInstanceOf(Command::class, $loader->get('foo'));
41         $this->assertInstanceOf(Command::class, $loader->get('bar'));
42     }
43
44     /**
45      * @expectedException \Symfony\Component\Console\Exception\CommandNotFoundException
46      */
47     public function testGetUnknownCommandThrows()
48     {
49         (new ContainerCommandLoader(new ServiceLocator(array()), array()))->get('unknown');
50     }
51
52     public function testGetCommandNames()
53     {
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'));
58
59         $this->assertSame(array('foo', 'bar'), $loader->getNames());
60     }
61 }