2016-07-19 18:28:21 +02:00
|
|
|
<?php
|
2019-10-05 17:26:10 +02:00
|
|
|
|
2017-10-12 10:13:20 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2016-07-19 18:28:21 +02:00
|
|
|
namespace ShlinkioTest\Shlink\CLI\Factory;
|
|
|
|
|
|
2020-01-01 21:11:53 +01:00
|
|
|
use Laminas\ServiceManager\ServiceManager;
|
2023-02-09 20:42:18 +01:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2017-03-24 20:34:18 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-19 18:28:21 +02:00
|
|
|
use Shlinkio\Shlink\CLI\Factory\ApplicationFactory;
|
2024-10-16 08:55:38 +02:00
|
|
|
use Shlinkio\Shlink\Core\Config\Options\AppOptions;
|
2023-06-18 10:51:59 +02:00
|
|
|
use ShlinkioTest\Shlink\CLI\Util\CliTestUtils;
|
2019-02-26 22:56:43 +01:00
|
|
|
|
2016-07-19 18:28:21 +02:00
|
|
|
class ApplicationFactoryTest extends TestCase
|
|
|
|
|
{
|
2019-12-29 22:27:00 +01:00
|
|
|
private ApplicationFactory $factory;
|
2016-07-19 18:28:21 +02:00
|
|
|
|
2022-09-11 12:02:49 +02:00
|
|
|
protected function setUp(): void
|
2016-07-19 18:28:21 +02:00
|
|
|
{
|
|
|
|
|
$this->factory = new ApplicationFactory();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-09 20:42:18 +01:00
|
|
|
#[Test]
|
2019-08-04 11:16:46 +02:00
|
|
|
public function allCommandsWhichAreServicesAreAdded(): void
|
2016-07-19 18:28:21 +02:00
|
|
|
{
|
|
|
|
|
$sm = $this->createServiceManager([
|
|
|
|
|
'commands' => [
|
2018-11-17 18:40:47 +01:00
|
|
|
'foo' => 'foo',
|
|
|
|
|
'bar' => 'bar',
|
|
|
|
|
'baz' => 'baz',
|
2016-07-19 18:28:21 +02:00
|
|
|
],
|
|
|
|
|
]);
|
2025-12-15 14:17:36 +01:00
|
|
|
$sm->setService('foo', CliTestUtils::createCommandStub('foo'));
|
|
|
|
|
$sm->setService('bar', CliTestUtils::createCommandStub('bar'));
|
2016-07-19 18:28:21 +02:00
|
|
|
|
2019-08-04 11:16:46 +02:00
|
|
|
$instance = ($this->factory)($sm);
|
2018-11-17 18:40:47 +01:00
|
|
|
|
2020-10-04 00:35:14 +02:00
|
|
|
self::assertTrue($instance->has('foo'));
|
|
|
|
|
self::assertTrue($instance->has('bar'));
|
|
|
|
|
self::assertFalse($instance->has('baz'));
|
2016-07-19 18:28:21 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-17 18:40:47 +01:00
|
|
|
private function createServiceManager(array $config = []): ServiceManager
|
2016-07-19 18:28:21 +02:00
|
|
|
{
|
2026-05-22 08:42:47 +02:00
|
|
|
return new ServiceManager([
|
|
|
|
|
'services' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'cli' => $config,
|
|
|
|
|
],
|
|
|
|
|
AppOptions::class => new AppOptions(),
|
2016-07-19 18:28:21 +02:00
|
|
|
],
|
2026-05-22 08:42:47 +02:00
|
|
|
]);
|
2016-07-19 18:28:21 +02:00
|
|
|
}
|
|
|
|
|
}
|