throwableMethod(); * * CatchException::assertThat()->isInstanceOf(ThrowableClass::class); * * @package Ouzo\Tests */ class CatchException { /** @var Throwable|null */ public static $exception; /** * @param object $object * @return CatchExceptionObject */ public static function when($object) { self::$exception = null; return new CatchExceptionObject($object); } /** * @return CatchExceptionAssert */ public static function assertThat() { return new CatchExceptionAssert(self::$exception); } /** * @return Throwable */ public static function get() { return self::$exception; } /** * * //given * class Color { * public function __construct($firstParam, $secondParam, $thirdParam){ * throw new Exception(); * } * } * * class ColorTest extends TestCase{ * public function testConstructor(){ * //given * $params =["firstParam", ["secondParam"], 3]; * * //when * CatchException::inConstructor(Color::class, $params); * * //then * CatchException::assertThat()->isInstanceOf(Exception::class); * } * } * * @param $className * @param array $params * @return object */ public static function inConstructor($className, array $params) { try { $class = new ReflectionClass($className); return $class->newInstanceArgs($params); } catch (Exception $e) { self::$exception = $e; } } }