/** * are there any handlers registered on a given stream for a given event? * * @param EventStream $stream * the stream to check * @param string $eventName * the event to check for * @return boolean * TRUE if there are handlers registered for $eventName * FALSE otherwise */ public static function check(EventStream $stream, $eventName) { // this avoid PHP runtime errors if (!IsEventName::check($eventName)) { return false; } return isset($stream->{$eventName}); }
/** * throw exceptions if we do not have the class name of a valid event * * @param mixed $eventName * the data to check * @param string $exception * the exception to throw if our requirement is not met * @return void */ public static function check($eventName, $exception = E4xx_NotAnEvent::class) { if (!IsEventName::check($eventName)) { throw new $exception($eventName); } }
/** * @covers ::check * @dataProvider provideInvalidEventNames */ public function testReturnsFalseForInvalidEventNames($eventName, $expectedResult) { // ---------------------------------------------------------------- // setup your test // ---------------------------------------------------------------- // perform the change $actualResult = IsEventName::check($eventName); // ---------------------------------------------------------------- // test the results $this->assertFalse($actualResult); }