-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleLoggerTest.php
More file actions
65 lines (56 loc) · 2.43 KB
/
Copy pathConsoleLoggerTest.php
File metadata and controls
65 lines (56 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace WonderNetwork\SlimKernel\ConsoleLogger;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use WonderNetwork\SlimKernel\Cli\Logging\ConsoleHandlerEventSubscriber;
use WonderNetwork\SlimKernel\Cli\Logging\ConsoleIoStack;
use WonderNetwork\SlimKernel\Cli\Logging\CurrentConsoleInput;
use WonderNetwork\SlimKernel\Cli\Logging\CurrentConsoleOutput;
use WonderNetwork\SlimKernel\Cli\Logging\Handler\ConsoleHandler;
use WonderNetwork\SlimKernel\EventDispatcher\EventSubscribersCollection;
use WonderNetwork\SlimKernel\KernelBuilder;
use WonderNetwork\SlimKernel\ServiceFactory\SymfonyConsoleServiceFactory;
use function DI\autowire;
final class ConsoleLoggerTest extends TestCase {
public function testConsoleLogger(): void {
$rootPath = realpath(__DIR__.'/../Resources/ConsoleLogger');
if (false === $rootPath) {
$this->fail('Root path does not exist');
}
$container = KernelBuilder::start($rootPath)
->add(
[
ConsoleIoStack::class => autowire(),
ConsoleHandler::class => autowire(),
CurrentConsoleOutput::class => autowire(),
CurrentConsoleInput::class => autowire(),
LoggerInterface::class => function (ConsoleHandler $consoleHandler) {
$logger = new Logger('channel');
$logger->pushHandler($consoleHandler);
return $logger;
},
ConsoleHandlerEventSubscriber::class => autowire(),
],
)
->register(
EventSubscribersCollection::start()
->add(ConsoleHandlerEventSubscriber::class),
)
->register(
new SymfonyConsoleServiceFactory(
path: '/src/*Command.php',
),
)
->build();
/** @var Application $app */
$app = $container->get(Application::class);
$output = new BufferedOutput();
$app->run(input: new ArrayInput(['echo', '-vv', 'message' => 'Hello World']), output: $output);
self::assertStringContainsString("channel info Received Hello World", $output->fetch());
}
}