2020-01-27 15:11:35 -05:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Aviat\Kilo\Tests;
|
|
|
|
|
|
|
|
use Aviat\Kilo\Event;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class EventTest extends TestCase {
|
|
|
|
public function testRequiresValidEvent(): void
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
2020-01-29 16:13:05 -05:00
|
|
|
Event::on('badEventName', fn () => null);
|
2020-01-27 15:11:35 -05:00
|
|
|
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
Event::fire('badEventName', []);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBindAndFire(): void
|
|
|
|
{
|
|
|
|
$fn = static function($value = false) {
|
|
|
|
static::assertTrue($value);
|
|
|
|
};
|
2020-01-29 16:13:05 -05:00
|
|
|
Event::on(Event::INPUT_KEY, $fn);
|
|
|
|
Event::fire(Event::INPUT_KEY, TRUE);
|
2020-01-27 15:11:35 -05:00
|
|
|
}
|
|
|
|
}
|