예제 #1
0
파일: call.php 프로젝트: xihewang/atoum
 public function setCall(test\adapter\call $call = null)
 {
     if ($call === null) {
         $call = new test\adapter\call();
     }
     if ($this->call !== null) {
         $call->copy($this->call);
     }
     $this->call = $call;
     return $this;
 }
예제 #2
0
 public function decorate(call $call)
 {
     $string = '';
     $function = $call->getFunction();
     if ($function !== null) {
         $string = $function . '(';
         $arguments = $call->getArguments();
         if ($arguments === null) {
             $string .= '*';
         } else {
             $string .= $this->argumentsDecorator->decorate($call->getArguments());
         }
         $string .= ')';
     }
     return $string;
 }
예제 #3
0
 public function getCalls(test\adapter\call $call = null, $identical = false)
 {
     if ($call !== null) {
         $this->checkMethod($call->getFunction());
     }
     return parent::getCalls($call, $identical);
 }
예제 #4
0
파일: calls.php 프로젝트: xihewang/atoum
 public function testHasAfterIdenticalTo()
 {
     $this->if($calls = new testedClass())->then->boolean($calls->hasAfterIdenticalTo(new adapter\call(uniqid()), rand(1, PHP_INT_MAX)))->isFalse()->if($calls[] = $call1 = new adapter\call(uniqid()))->then->boolean($calls->hasAfterIdenticalTo(new adapter\call(uniqid()), rand(1, PHP_INT_MAX)))->isFalse()->boolean($calls->hasAfterIdenticalTo(new adapter\call($call1), 0))->isFalse()->boolean($calls->hasAfterIdenticalTo(new adapter\call($call1), 1))->isFalse()->boolean($calls->hasAfterIdenticalTo(new adapter\call($call1), rand(2, PHP_INT_MAX)))->isFalse()->if($calls[] = $call2 = new adapter\call(uniqid(), array()))->then->boolean($calls->hasAfterIdenticalTo(new adapter\call(uniqid()), 1))->isFalse()->boolean($calls->hasAfterIdenticalTo($call1, 1))->isFalse()->boolean($calls->hasAfterIdenticalTo($call1, 2))->isFalse()->boolean($afterCalls = $calls->hasAfterIdenticalTo($call2, 1))->isTrue()->boolean($calls->hasAfterIdenticalTo($call2, 2))->isFalse()->if($calls[] = $call3 = new adapter\call(uniqid(), array($object = new \mock\object())))->if($calls[] = $call4 = new adapter\call($call3->getFunction(), array(clone $object)))->and($calls[] = $call5 = new adapter\call(uniqid(), array()))->then->boolean($calls->hasAfterIdenticalTo(new adapter\call(uniqid()), 1))->isFalse()->boolean($calls->hasAfterIdenticalTo($call1, 1))->isFalse()->boolean($calls->hasAfterIdenticalTo($call1, 2))->isFalse()->boolean($afterCalls = $calls->hasAfterIdenticalTo($call2, 1))->isTrue()->boolean($calls->hasAfterIdenticalTo($call2, 2))->isFalse()->boolean($afterCalls = $calls->hasAfterIdenticalTo($call3, 1))->isTrue()->boolean($afterCalls = $calls->hasAfterIdenticalTo($call3, 3))->isFalse()->boolean($afterCalls = $calls->hasAfterIdenticalTo($call4, 1))->isTrue();
 }
예제 #5
0
 protected static function getKey(adapter\call $call)
 {
     return strtolower($call->getFunction());
 }
예제 #6
0
파일: call.php 프로젝트: xihewang/atoum
 public function testIsIdenticalTo()
 {
     $this->if($call1 = new testedClass())->and($call2 = new testedClass())->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call1 = new testedClass(uniqid()))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call2 = new testedClass(uniqid()))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call1 = new testedClass())->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call1 = new testedClass($function = uniqid()))->and($call2 = new testedClass($function))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call1 = new testedClass($function, array()))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call2 = new testedClass($function, array()))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call1 = new testedClass($function, array($argument = uniqid())))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call2 = new testedClass($function, array($argument)))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call1 = new testedClass($function, $arguments = array(uniqid(), uniqid())))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call2 = new testedClass($function, $arguments))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call1 = new testedClass($function, $arguments = array($arg1 = uniqid(), $arg2 = uniqid(), $arg3 = new \mock\object())))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call2 = new testedClass($function, $arguments))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isTrue()->if($call2 = new testedClass($function, array($arg1, $arg2, clone $arg3)))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call2 = new testedClass($function, array($arg3, $arg2, $arg1)))->then->boolean($call1->isIdenticalTo($call2))->isFalse()->boolean($call2->isIdenticalTo($call1))->isFalse()->if($call1 = new testedClass($function))->and($call2 = new testedClass($function, array($object = new \mock\object())))->then->boolean($call1->isIdenticalTo($call2))->isTrue()->boolean($call2->isIdenticalTo($call1))->isFalse();
 }
예제 #7
0
 public function testNever()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->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->never();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Call is undefined')->if($asserter->call('foo'))->then->object($asserter->never())->isIdenticalTo($asserter)->if($call = new test\adapter\call('foo', null, new decorators\addClass($mock)))->and($mock->foo($usedArg = uniqid()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->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($usedArg)))->if($mock->getMockController()->resetCalls())->and($asserter->withArguments($arg = uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter)->if($mock->foo($arg))->then->exception(function () use($asserter) {
         $asserter->never();
     })->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($arg)))->if($mock->foo($arg))->then->exception(function () use($asserter) {
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 2 times instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)))->if($mock->foo($arg))->then->exception(function () use($asserter, &$message) {
         $asserter->never($message = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage($message)->if($asserter->withArguments(uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter);
 }
예제 #8
0
 public function testNever()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserters\\adapter\\exceptions\\logic')->hasMessage('Adapter is undefined')->if($asserter->setWith($adapter = new test\adapter()))->then->exception(function () use($asserter) {
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserters\\adapter\\exceptions\\logic')->hasMessage('Call is undefined')->if($call = new test\adapter\call('md5'))->and($asserter->call('md5'))->then->object($asserter->never())->isIdenticalTo($asserter)->if($adapter->md5($usedArg = uniqid()))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->never();
     })->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($usedArg)))->if($adapter->resetCalls())->and($asserter->withArguments($arg = uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter)->if($adapter->md5($arg))->then->exception(function () use(&$line, $asserter) {
         $line = __LINE__;
         $asserter->never();
     })->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($arg)))->if($adapter->md5($arg))->then->exception(function () use(&$otherLine, $asserter) {
         $otherLine = __LINE__;
         $asserter->never();
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('%s is called 2 times instead of 0'), $asserter->getCall()) . PHP_EOL . '[1] ' . $call->setArguments(array($arg)) . PHP_EOL . '[2] ' . $call->setArguments(array($arg)))->if($asserter->withArguments(uniqid()))->then->object($asserter->never())->isIdenticalTo($asserter);
 }