/** * throws exceptions if $item is not a PHP class or interface that exists * * this is a wrapper around our IsDefinedObjectType check * * @param mixed $item * the container to check * @param string $eNoSuchClass * the exception to throw if $item isn't a valid PHP class * @param string $eUnsupportedType * the exception to throw if $item isn't something that we can check * @return void */ public static function check($item, $eNoSuchClass = E4xx_NoSuchClass::class, $eUnsupportedType = E4xx_UnsupportedType::class) { RequireStringy::check($item, $eUnsupportedType); if (trait_exists($item)) { throw new $eUnsupportedType(SimpleType::from($item)); } // make sure we have a PHP class that exists if (!IsDefinedObjectType::check($item)) { throw new $eNoSuchClass($item); } }
/** * @covers ::__invoke * @covers ::check * @dataProvider provideScalarsToTest */ public function testReturnsFalseForEverythingElse($data, $expectedResult) { // ---------------------------------------------------------------- // setup your test $obj = new IsDefinedObjectType(); // ---------------------------------------------------------------- // perform the change $actualResult1 = $obj($data); $actualResult2 = IsDefinedObjectType::check($data); // ---------------------------------------------------------------- // test the results $this->assertFalse($actualResult1); $this->assertFalse($actualResult2); }