Beacon/tests/Unit/EventTestingHelpersTest.php

43 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Phred\Beacon\Tests\Unit;
use PHPUnit\Framework\TestCase;
use Phred\Beacon\EventDispatcher;
use Phred\Beacon\ListenerProvider;
use Phred\Beacon\EventCollector;
use Phred\Beacon\EventAssertions;
class EventTestingHelpersTest extends TestCase
{
use EventAssertions;
public function test_it_collects_events(): void
{
$collector = new EventCollector();
$event = new \stdClass();
$collector($event);
$this->assertTrue($collector->hasDispatched('stdClass'));
$this->assertCount(1, $collector->getEvents());
$this->assertSame($event, $collector->getEvents()[0]);
}
public function test_assertions_work_correctly(): void
{
// Note: Manual registration for the test of the trait itself
$this->eventCollector = new EventCollector();
$provider = new ListenerProvider();
$provider->addListener('*', $this->eventCollector);
$dispatcher = new EventDispatcher($provider);
$dispatcher->dispatch(new \stdClass());
$this->assertEventDispatched('stdClass');
$this->assertEventNotDispatched('RuntimeException');
}
}