/** * throws exceptions if $item is not a PHP class that exists * * this is a wrapper around our IsDefinedClass check * * @param mixed $item * the container to check * @param string $exception * the class to use when throwing an exception * @return void */ public static function check($item, $exception = E4xx_UnsupportedType::class) { // make sure we have a PHP class that exists if (!IsDefinedClass::check($item)) { throw new $exception(SimpleType::from($item)); } }
/** * is $eventName the name of an Event class? * * @param mixed $eventName * the data to check * @return boolean * TRUE if $eventName is the name of an Event class * FALSE otherwise */ public static function check($eventName) { // we only want valid class names, not compatible objects if (!IsDefinedClass::check($eventName)) { return false; } return IsCompatibleWith::check($eventName, Event::class); }
/** * @covers ::__invoke * @covers ::check * @dataProvider provideScalarsToTest */ public function testReturnsFalseForEverythingElse($data, $expectedResult) { // ---------------------------------------------------------------- // setup your test $obj = new IsDefinedClass(); // ---------------------------------------------------------------- // perform the change $actualResult1 = $obj($data); $actualResult2 = IsDefinedClass::check($data); // ---------------------------------------------------------------- // test the results $this->assertFalse($actualResult1); $this->assertFalse($actualResult2); }