2016-07-19 11:28:21 -05:00
|
|
|
<?php
|
2019-10-05 10:26:10 -05:00
|
|
|
|
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;
|
|
|
|
|
2020-01-01 14:11:53 -06:00
|
|
|
use Laminas\ServiceManager\ServiceManager;
|
2023-02-09 13:42:18 -06:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
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;
|
2023-06-18 03:51:59 -05:00
|
|
|
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
2019-02-26 15:56:43 -06:00
|
|
|
|
2016-07-19 11:28:21 -05:00
|
|
|
class ApplicationFactoryTest extends TestCase
|
|
|
|
{
|
2019-12-29 15:27:00 -06:00
|
|
|
private ApplicationFactory $factory;
|
2016-07-19 11:28:21 -05:00
|
|
|
|
2022-09-11 05:02:49 -05:00
|
|
|
protected function setUp(): void
|
2016-07-19 11:28:21 -05:00
|
|
|
{
|
|
|
|
$this->factory = new ApplicationFactory();
|
|
|
|
}
|
|
|
|
|
2023-02-09 13:42:18 -06:00
|
|
|
#[Test]
|
2019-08-04 04:16:46 -05:00
|
|
|
public function allCommandsWhichAreServicesAreAdded(): void
|
2016-07-19 11:28:21 -05:00
|
|
|
{
|
|
|
|
$sm = $this->createServiceManager([
|
|
|
|
'commands' => [
|
2018-11-17 11:40:47 -06:00
|
|
|
'foo' => 'foo',
|
|
|
|
'bar' => 'bar',
|
|
|
|
'baz' => 'baz',
|
2016-07-19 11:28:21 -05:00
|
|
|
],
|
|
|
|
]);
|
2023-06-18 03:51:59 -05:00
|
|
|
$sm->setService('foo', CliTestUtils::createCommandMock('foo'));
|
|
|
|
$sm->setService('bar', CliTestUtils::createCommandMock('bar'));
|
2016-07-19 11:28:21 -05:00
|
|
|
|
2019-08-04 04:16:46 -05:00
|
|
|
$instance = ($this->factory)($sm);
|
2018-11-17 11:40:47 -06:00
|
|
|
|
2020-10-03 17:35:14 -05:00
|
|
|
self::assertTrue($instance->has('foo'));
|
|
|
|
self::assertTrue($instance->has('bar'));
|
|
|
|
self::assertFalse($instance->has('baz'));
|
2016-07-19 11:28:21 -05:00
|
|
|
}
|
|
|
|
|
2018-11-17 11:40:47 -06:00
|
|
|
private function createServiceManager(array $config = []): ServiceManager
|
2016-07-19 11:28:21 -05:00
|
|
|
{
|
|
|
|
return new ServiceManager(['services' => [
|
|
|
|
'config' => [
|
2019-09-12 01:09:17 -05:00
|
|
|
'cli' => $config,
|
2016-07-19 11:28:21 -05:00
|
|
|
],
|
2016-08-15 02:52:44 -05:00
|
|
|
AppOptions::class => new AppOptions(),
|
2016-07-19 11:28:21 -05:00
|
|
|
]]);
|
|
|
|
}
|
|
|
|
}
|