when($result = new SUT('foo', 42, '/hoa/flatland', 153)) ->then ->object($result) ->isInstanceOf('Hoa\Exception\Exception'); } public function case_get_message() { $this ->given($exception = new SUT('foo', 42, '/hoa/flatland', 153)) ->when($result = $exception->raise()) ->then ->string($result) ->isEqualTo( '{main}: (42) foo' . "\n" . 'in /hoa/flatland at line 153.' ); } public function case_disable_error_handler() { $this ->given( $this->function->restore_error_handler = function () use (&$called) { $called = true; return null; } ) ->when($result = SUT::enableErrorHandler(false)) ->then ->variable($result) ->isNull() ->boolean($called) ->isTrue(); } public function case_enable_error_handler() { $self = $this; $this ->given( $this->function->set_error_handler = function ($handler) use ($self, &$called) { $called = true; $self ->object($handler) ->isInstanceOf('Closure') ->let($reflection = new \ReflectionObject($handler)) ->array($invokeParameters = $reflection->getMethod('__invoke')->getParameters()) ->hasSize(5) ->string($invokeParameters[0]->getName()) ->isEqualTo('no') ->string($invokeParameters[1]->getName()) ->isEqualTo('str') ->string($invokeParameters[2]->getName()) ->isEqualTo('file') ->boolean($invokeParameters[2]->isOptional()) ->isTrue() ->string($invokeParameters[3]->getName()) ->isEqualTo('line') ->boolean($invokeParameters[3]->isOptional()) ->isTrue() ->string($invokeParameters[4]->getName()) ->isEqualTo('ctx') ->boolean($invokeParameters[4]->isOptional()) ->isTrue(); return null; } ) ->when($result = SUT::enableErrorHandler()) ->then ->variable($result) ->isNull() ->boolean($called) ->isTrue(); } public function case_error_handler() { $this ->given(SUT::enableErrorHandler()) ->exception(function () { ++$i; }) ->isInstanceOf('Hoa\Exception\Error') ->hasMessage('Undefined variable: i'); } }