public function testGetLastValue() { $this->variable(sut::getLastValue())->isNull()->if($asserter = new sut(new asserter\generator()))->and($asserter->setWith(function () use(&$exception) { $exception = new \exception(); throw $exception; }))->then->object(sut::getLastValue())->isIdenticalTo($exception)->and($asserter->setWith(function () use(&$otherException) { $otherException = new \exception(); throw $otherException; }))->then->object(sut::getLastValue())->isIdenticalTo($otherException); }
public function testHasNestedException() { $this->if($asserter = new asserters\exception($generator = new asserter\generator()))->then->boolean($asserter->wasSet())->isFalse()->exception(function () use($asserter) { $asserter->hasNestedException(); })->isInstanceOf('logicException')->hasMessage('Exception is undefined')->if($asserter->setWith(new atoum\exceptions\runtime('', 0)))->then->exception(function () use($asserter) { $asserter->hasNestedException(); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain any nested exception'))->exception(function () use($asserter) { $asserter->hasNestedException(new \exception()); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain this nested exception'))->if($asserter->setWith(new atoum\exceptions\runtime('', 0, $nestedException = new \exception())))->then->object($asserter->hasNestedException())->isIdenticalTo($asserter)->object($asserter->hasNestedException($nestedException))->isIdenticalTo($asserter)->exception(function () use($asserter) { $asserter->hasNestedException(new \exception()); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($generator->getLocale()->_('exception does not contain this nested exception')); }
public function should_invoke_method_on_provided_object_and_return_exception_asserter_when_asserting_on_thrown_exception() { $this->given($generator = new atoum\asserter\generator(), $phpClass = new \mock\mageekguy\atoum\asserters\phpClass($generator), $test = new \mock\mageekguy\atoum\test(), $object = new \mock\dummy(), $object->getMockController()->disableMethodChecking(), $method = uniqid('A'), $this->calling($phpClass)->hasMethod = $phpClass, $this->calling($object)->{$method}->throw = $exception = new \exception(), $this->calling($test)->getTestedClassName = $testedClassName = get_class($object), $exceptionAsserter = new atoum\asserters\exception($generator))->if($this->newTestedInstance($generator, $phpClass), $this->testedInstance->setWithTest($test)->setMethod($method))->then->invoking('setInstance', $object)->shouldReturn->object->isTestedInstance->invoking('throws')->shouldReturn->object->isEqualTo($exceptionAsserter->setWith($exception))->mock($object)->call($method)->once(); }