Skip to content

Commit 4b098a4

Browse files
committed
Tests: more tests
1 parent 46f67cb commit 4b098a4

5 files changed

Lines changed: 118 additions & 2 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types = 1);
2+
3+
use Contributte\EventDispatcher\DI\EventDispatcherExtension;
4+
use Contributte\Tester\Toolkit;
5+
use Contributte\Tester\Utils\ContainerBuilder;
6+
use Contributte\Tester\Utils\Neonkit;
7+
use Nette\DI\Compiler;
8+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9+
use Tester\Assert;
10+
use Tracy\Bridges\Nette\TracyExtension;
11+
12+
require_once __DIR__ . '/../../bootstrap.php';
13+
14+
// Disable autoloading
15+
Toolkit::test(function (): void {
16+
$container = ContainerBuilder::of()
17+
->withCompiler(function (Compiler $compiler): void {
18+
$compiler->addExtension('tracy', new TracyExtension());
19+
$compiler->addExtension('events', new EventDispatcherExtension());
20+
$compiler->addConfig(Neonkit::load(<<<'NEON'
21+
events:
22+
autoload: false
23+
services:
24+
foo: Tests\Fixtures\FooSubscriber
25+
NEON
26+
));
27+
})->build();
28+
29+
/** @var EventDispatcherInterface $em */
30+
$em = $container->getByType(EventDispatcherInterface::class);
31+
32+
Assert::false($em->hasListeners());
33+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
use Contributte\EventDispatcher\DI\EventDispatcherExtension;
4+
use Contributte\EventDispatcher\Tracy\EventPanel;
5+
use Contributte\Tester\Toolkit;
6+
use Contributte\Tester\Utils\ContainerBuilder;
7+
use Contributte\Tester\Utils\Neonkit;
8+
use Nette\DI\Compiler;
9+
use Tester\Assert;
10+
use Tracy\Bar;
11+
use Tracy\Bridges\Nette\TracyExtension;
12+
13+
require_once __DIR__ . '/../../bootstrap.php';
14+
15+
// Add Tracy panel
16+
Toolkit::test(function (): void {
17+
$container = ContainerBuilder::of()
18+
->withCompiler(function (Compiler $compiler): void {
19+
$compiler->addExtension('tracy', new TracyExtension());
20+
$compiler->addExtension('events', new EventDispatcherExtension());
21+
$compiler->addConfig(Neonkit::load(<<<'NEON'
22+
events:
23+
debug: true
24+
NEON
25+
));
26+
})->build();
27+
28+
$container->initialize();
29+
30+
/** @var Bar $bar */
31+
$bar = $container->getByType(Bar::class);
32+
33+
Assert::notNull($bar->getPanel(EventPanel::class));
34+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types = 1);
2+
3+
use Contributte\EventDispatcher\DI\EventDispatcherExtension;
4+
use Contributte\EventDispatcher\Diagnostics\DebugDispatcher;
5+
use Contributte\Tester\Toolkit;
6+
use Contributte\Tester\Utils\ContainerBuilder;
7+
use Contributte\Tester\Utils\Neonkit;
8+
use Nette\DI\Compiler;
9+
use Tester\Assert;
10+
11+
require_once __DIR__ . '/../../bootstrap.php';
12+
13+
// Disable autoloading
14+
Toolkit::test(function (): void {
15+
$container = ContainerBuilder::of()
16+
->withCompiler(function (Compiler $compiler): void {
17+
$compiler->addExtension('events', new EventDispatcherExtension());
18+
$compiler->addConfig(Neonkit::load(<<<'NEON'
19+
events:
20+
loggers:
21+
- Tests\Fixtures\DummyLogger()
22+
NEON
23+
));
24+
})->build();
25+
26+
/** @var DebugDispatcher $dd */
27+
$dd = $container->getByType(DebugDispatcher::class);
28+
29+
Assert::notNull($dd->getLoggers());
30+
});

tests/Cases/DI/EventExtension.phpt renamed to tests/Cases/DI/EventExtension.subscriber.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Tests\Fixtures\PrioritizedSubscriber;
1616

1717
require_once __DIR__ . '/../../bootstrap.php';
1818

19-
// Dispatch event with NO defined subscriber for event
19+
// No defined subscriber for event
2020
Toolkit::test(function (): void {
2121
$container = ContainerBuilder::of()
2222
->withCompiler(function (Compiler $compiler): void {
@@ -172,7 +172,7 @@ Toolkit::test(function (): void {
172172
Assert::equal([$event], $subscriber->onCall);
173173
});
174174

175-
// Dispatch event with NO subscribers at all
175+
// No subscribers at all
176176
Toolkit::test(function (): void {
177177
$container = ContainerBuilder::of()
178178
->withCompiler(function (Compiler $compiler): void {

‎tests/Fixtures/DummyLogger.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Tests\Fixtures;
4+
5+
use Psr\Log\AbstractLogger;
6+
use Stringable;
7+
8+
final class DummyLogger extends AbstractLogger
9+
{
10+
11+
/**
12+
* @param array<mixed> $context
13+
*/
14+
public function log(mixed $level, Stringable|string $message, array $context = []): void
15+
{
16+
// Nothing
17+
}
18+
19+
}

0 commit comments

Comments
 (0)