Beispiel #1
0
 public function testExactly()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Mock is undefined')->if($asserter->setWith($mock = new \mock\mageekguy\atoum\tests\units\asserters\dummy()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Call is undefined')->if($asserter->call('foo'))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 0 time instead of 2'), $asserter->getCall()))->if($call = new test\adapter\call('foo', null, new decorators\addClass($mock)))->and($mock->foo($usedArg = uniqid()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)))->if($mock->foo($otherUsedArg = uniqid()))->then->object($asserter->exactly(2))->isIdenticalTo($asserter)->if($mock->foo($anOtherUsedArg = uniqid()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($otherUsedArg)) . PHP_EOL . '[3] ' . $call->setArguments(array($anOtherUsedArg)))->if($mock->getMockController()->resetCalls())->and($asserter->withArguments($arg = uniqid()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 0 time instead of 2'), $asserter->getCall()))->if($mock->foo($usedArg = uniqid()))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 0 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)))->if($mock->foo($arg))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 1 time instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)))->if($mock->foo($arg))->then->object($asserter->exactly(2))->isIdenticalTo($asserter)->if($mock->foo($arg))->then->exception(function () use($asserter) {
         $asserter->exactly(2);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 3 times instead of 2'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($usedArg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)) . PHP_EOL . '[3] ' . $call->setArguments(array($arg)) . PHP_EOL . '[4] ' . $call->setArguments(array($arg)))->if($call = new test\adapter\call('fooWithSeveralArguments', null, new decorators\addClass($mock)))->and($asserter->call('fooWithSeveralArguments'))->then->object($asserter->exactly(0))->isIdenticalTo($asserter)->exception(function () use($asserter) {
         $asserter->exactly(1);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 0 time instead of 1'), $asserter->getCall()))->if($mock->fooWithSeveralArguments(1, 2, 3, 4, 5))->then->exception(function () use($asserter) {
         $asserter->exactly(0);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5)))->object($asserter->exactly(1))->isIdenticalTo($asserter)->object($asserter->withArguments(1, 2, 3, 4, 5)->exactly(1))->isIdenticalTo($asserter)->object($asserter->withAtLeastArguments(array(1 => 2, 3 => 4))->exactly(1))->isIdenticalTo($asserter)->object($asserter->withAtLeastArguments(array(1 => 2, 3 => rand(6, PHP_INT_MAX)))->exactly(0))->isIdenticalTo($asserter)->exception(function () use($asserter) {
         $asserter->withAtLeastArguments(array(1 => 2, 3 => 4))->exactly(0);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 1 time instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5)))->object($asserter->withIdenticalArguments(1, 2, 3, 4, 5)->exactly(1))->isIdenticalTo($asserter)->exception(function () use($asserter) {
         $asserter->withAtLeastIdenticalArguments(array(1 => '2', 3 => 4))->exactly(1);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 0 time instead of 1'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array(1, 2, 3, 4, 5)));
 }