From f8894b971a7ef76518195637ca15e87a7ea512b1 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 27 Jan 2020 15:11:35 -0500 Subject: [PATCH] Add basic event system --- src/Event.php | 47 +++++++++++++++++++++++++++++++++++++++++++++ tests/EventTest.php | 28 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/Event.php create mode 100644 tests/EventTest.php diff --git a/src/Event.php b/src/Event.php new file mode 100644 index 0000000..32bdc69 --- /dev/null +++ b/src/Event.php @@ -0,0 +1,47 @@ +expectException(InvalidArgumentException::class); + Event::bind('badEventName', fn () => null); + + $this->expectException(InvalidArgumentException::class); + Event::fire('badEventName', []); + } + + public function testBindAndFire(): void + { + $fn = static function($value = false) { + static::assertTrue($value); + }; + Event::bind(EventType::INPUT_KEY, $fn); + Event::fire(EventType::INPUT_KEY, TRUE); + } +}