2016-07-19 19:28:21 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-19 19:28:21 +03:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Factory;
|
|
|
|
|
2017-03-24 22:34:18 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-11-17 20:40:47 +03:00
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophecy\ObjectProphecy;
|
2016-07-19 19:28:21 +03:00
|
|
|
use Shlinkio\Shlink\CLI\Factory\ApplicationFactory;
|
2016-08-15 10:52:44 +03:00
|
|
|
use Shlinkio\Shlink\Core\Options\AppOptions;
|
2016-07-19 19:28:21 +03:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
2019-02-27 00:56:43 +03:00
|
|
|
|
2016-07-19 19:28:21 +03:00
|
|
|
class ApplicationFactoryTest extends TestCase
|
|
|
|
{
|
2018-11-20 21:30:27 +03:00
|
|
|
/** @var ApplicationFactory */
|
2018-11-20 21:37:22 +03:00
|
|
|
private $factory;
|
2016-07-19 19:28:21 +03:00
|
|
|
|
2019-02-16 12:53:45 +03:00
|
|
|
public function setUp(): void
|
2016-07-19 19:28:21 +03:00
|
|
|
{
|
|
|
|
$this->factory = new ApplicationFactory();
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:28:34 +03:00
|
|
|
/** @test */
|
2019-08-04 12:16:46 +03:00
|
|
|
public function allCommandsWhichAreServicesAreAdded(): void
|
2016-07-19 19:28:21 +03:00
|
|
|
{
|
|
|
|
$sm = $this->createServiceManager([
|
|
|
|
'commands' => [
|
2018-11-17 20:40:47 +03:00
|
|
|
'foo' => 'foo',
|
|
|
|
'bar' => 'bar',
|
|
|
|
'baz' => 'baz',
|
2016-07-19 19:28:21 +03:00
|
|
|
],
|
|
|
|
]);
|
2018-11-17 20:40:47 +03:00
|
|
|
$sm->setService('foo', $this->createCommandMock('foo')->reveal());
|
|
|
|
$sm->setService('bar', $this->createCommandMock('bar')->reveal());
|
2016-07-19 19:28:21 +03:00
|
|
|
|
|
|
|
/** @var Application $instance */
|
2019-08-04 12:16:46 +03:00
|
|
|
$instance = ($this->factory)($sm);
|
2018-11-17 20:40:47 +03:00
|
|
|
|
|
|
|
$this->assertTrue($instance->has('foo'));
|
|
|
|
$this->assertTrue($instance->has('bar'));
|
|
|
|
$this->assertFalse($instance->has('baz'));
|
2016-07-19 19:28:21 +03:00
|
|
|
}
|
|
|
|
|
2018-11-17 20:40:47 +03:00
|
|
|
private function createServiceManager(array $config = []): ServiceManager
|
2016-07-19 19:28:21 +03:00
|
|
|
{
|
|
|
|
return new ServiceManager(['services' => [
|
|
|
|
'config' => [
|
2019-09-12 09:09:17 +03:00
|
|
|
'cli' => $config,
|
2016-07-19 19:28:21 +03:00
|
|
|
],
|
2016-08-15 10:52:44 +03:00
|
|
|
AppOptions::class => new AppOptions(),
|
2016-07-19 19:28:21 +03:00
|
|
|
]]);
|
|
|
|
}
|
2018-11-17 20:40:47 +03:00
|
|
|
|
|
|
|
private function createCommandMock(string $name): ObjectProphecy
|
|
|
|
{
|
|
|
|
$command = $this->prophesize(Command::class);
|
|
|
|
$command->getName()->willReturn($name);
|
|
|
|
$command->getDefinition()->willReturn($name);
|
|
|
|
$command->isEnabled()->willReturn(true);
|
|
|
|
$command->getAliases()->willReturn([]);
|
|
|
|
$command->setApplication(Argument::type(Application::class))->willReturn(function () {
|
|
|
|
});
|
|
|
|
|
|
|
|
return $command;
|
|
|
|
}
|
2016-07-19 19:28:21 +03:00
|
|
|
}
|