2016-07-19 11:28:21 -05:00
|
|
|
<?php
|
2017-10-12 03:13:20 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-07-19 11:28:21 -05:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Factory;
|
|
|
|
|
2017-03-24 14:34:18 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-19 11:28:21 -05:00
|
|
|
use Shlinkio\Shlink\CLI\Factory\ApplicationFactory;
|
2016-08-15 02:52:44 -05:00
|
|
|
use Shlinkio\Shlink\Core\Options\AppOptions;
|
2016-07-19 11:28:21 -05:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
2016-08-15 02:52:44 -05:00
|
|
|
use Zend\I18n\Translator\Translator;
|
2016-07-19 11:28:21 -05:00
|
|
|
use Zend\ServiceManager\ServiceManager;
|
2018-10-28 02:34:02 -05:00
|
|
|
use function array_merge;
|
2016-07-19 11:28:21 -05:00
|
|
|
|
|
|
|
class ApplicationFactoryTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ApplicationFactory
|
|
|
|
*/
|
|
|
|
protected $factory;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->factory = new ApplicationFactory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function serviceIsCreated()
|
|
|
|
{
|
|
|
|
$instance = $this->factory->__invoke($this->createServiceManager(), '');
|
|
|
|
$this->assertInstanceOf(Application::class, $instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function allCommandsWhichAreServicesAreAdded()
|
|
|
|
{
|
|
|
|
$sm = $this->createServiceManager([
|
|
|
|
'commands' => [
|
|
|
|
'foo',
|
|
|
|
'bar',
|
|
|
|
'baz',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$sm->setService('foo', $this->prophesize(Command::class)->reveal());
|
|
|
|
$sm->setService('baz', $this->prophesize(Command::class)->reveal());
|
|
|
|
|
|
|
|
/** @var Application $instance */
|
|
|
|
$instance = $this->factory->__invoke($sm, '');
|
|
|
|
$this->assertInstanceOf(Application::class, $instance);
|
|
|
|
$this->assertCount(2, $instance->all());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createServiceManager($config = [])
|
|
|
|
{
|
|
|
|
return new ServiceManager(['services' => [
|
|
|
|
'config' => [
|
2016-08-15 02:52:44 -05:00
|
|
|
'cli' => array_merge($config, ['locale' => 'en']),
|
2016-07-19 11:28:21 -05:00
|
|
|
],
|
2016-08-15 02:52:44 -05:00
|
|
|
AppOptions::class => new AppOptions(),
|
|
|
|
Translator::class => Translator::factory([]),
|
2016-07-19 11:28:21 -05:00
|
|
|
]]);
|
|
|
|
}
|
|
|
|
}
|