shlink/module/CLI/test/Factory/ApplicationFactoryTest.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-19 19:28:21 +03:00
<?php
2019-10-05 18:26:10 +03:00
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;
2020-01-01 23:11:53 +03:00
use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\Attributes\Test;
2017-03-24 22:34:18 +03:00
use PHPUnit\Framework\TestCase;
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;
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
2016-07-19 19:28:21 +03:00
class ApplicationFactoryTest extends TestCase
{
use CliTestUtilsTrait;
2020-11-02 13:50:19 +03:00
2019-12-30 00:27:00 +03:00
private ApplicationFactory $factory;
2016-07-19 19:28:21 +03:00
protected function setUp(): void
2016-07-19 19:28:21 +03:00
{
$this->factory = new ApplicationFactory();
}
#[Test]
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
],
]);
$sm->setService('foo', $this->createCommandMock('foo'));
$sm->setService('bar', $this->createCommandMock('bar'));
2016-07-19 19:28:21 +03:00
$instance = ($this->factory)($sm);
2018-11-17 20:40:47 +03:00
2020-10-04 01:35:14 +03:00
self::assertTrue($instance->has('foo'));
self::assertTrue($instance->has('bar'));
self::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' => [
'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
]]);
}
}