상속: extends object
예제 #1
0
 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);
 }
예제 #2
0
 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'));
 }
예제 #3
0
 public function setAssertionManager(test\assertion\manager $assertionManager = null)
 {
     $this->assertionManager = $assertionManager ?: new test\assertion\manager();
     $test = $this;
     $this->assertionManager->setHandler('when', function ($mixed) use($test) {
         if ($mixed instanceof \closure) {
             $mixed();
         }
         return $test;
     })->setHandler('dump', function () use($test) {
         call_user_func_array('var_dump', func_get_args());
         return $test;
     })->setPropertyHandler('exception', function () {
         return asserters\exception::getLastValue();
     });
     $returnTest = function () use($test) {
         return $test;
     };
     $this->assertionManager->setHandler('assert', $returnTest)->setHandler('if', $returnTest)->setHandler('and', $returnTest)->setHandler('then', $returnTest)->setHandler('given', $returnTest);
     $asserterGenerator = $this->asserterGenerator;
     $this->assertionManager->setDefaultHandler(function ($asserter, $arguments) use($asserterGenerator) {
         return $asserterGenerator->getAsserterInstance($asserter, $arguments);
     });
     return $this;
 }
예제 #4
0
파일: test.php 프로젝트: hafeez3000/atoum
 public function setAssertionManager(test\assertion\manager $assertionManager = null)
 {
     $this->assertionManager = $assertionManager ?: new test\assertion\manager();
     $test = $this;
     $this->assertionManager->setHandler('when', function ($mixed) use($test) {
         if ($mixed instanceof \closure) {
             $mixed($test);
         }
         return $test;
     })->setHandler('assert', function ($case = null) use($test) {
         $test->stopCase();
         if ($case !== null) {
             $test->startCase($case);
         }
         return $test;
     })->setHandler('mockGenerator', function () use($test) {
         return $test->getMockGenerator();
     })->setHandler('mockClass', function ($class, $mockNamespace = null, $mockClass = null) use($test) {
         $test->getMockGenerator()->generate($class, $mockNamespace, $mockClass);
         return $test;
     })->setHandler('mockTestedClass', function ($mockNamespace = null, $mockClass = null) use($test) {
         $test->getMockGenerator()->generate($test->getTestedClassName(), $mockNamespace, $mockClass);
         return $test;
     })->setHandler('dump', function () use($test) {
         if ($test->debugModeIsEnabled() === true) {
             call_user_func_array('var_dump', func_get_args());
         }
         return $test;
     })->setHandler('stop', function () use($test) {
         if ($test->debugModeIsEnabled() === true) {
             throw new test\exceptions\stop();
         }
         return $test;
     })->setHandler('executeOnFailure', function ($callback) use($test) {
         if ($test->debugModeIsEnabled() === true) {
             $test->executeOnFailure($callback);
         }
         return $test;
     })->setHandler('dumpOnFailure', function ($variable) use($test) {
         if ($test->debugModeIsEnabled() === true) {
             $test->executeOnFailure(function () use($variable) {
                 var_dump($variable);
             });
         }
         return $test;
     })->setPropertyHandler('function', function () use($test) {
         return $test->getPhpMocker();
     })->setPropertyHandler('exception', function () {
         return asserters\exception::getLastValue();
     });
     $mockGenerator = $this->mockGenerator;
     $this->assertionManager->setPropertyHandler('nextMockedMethod', function () use($mockGenerator) {
         return $mockGenerator->getMethod();
     });
     $returnTest = function () use($test) {
         return $test;
     };
     $this->assertionManager->setHandler('if', $returnTest)->setHandler('and', $returnTest)->setHandler('then', $returnTest)->setHandler('given', $returnTest)->setMethodHandler('define', $returnTest)->setMethodHandler('let', $returnTest);
     $returnMockController = function (mock\aggregator $mock) {
         return $mock->getMockController();
     };
     $this->assertionManager->setHandler('calling', $returnMockController)->setHandler('ƒ', $returnMockController);
     $this->assertionManager->setHandler('resetMock', function (mock\aggregator $mock) {
         return $mock->getMockController()->resetCalls();
     })->setHandler('resetAdapter', function (test\adapter $adapter) {
         return $adapter->resetCalls();
     });
     $phpMocker = $this->phpMocker;
     $this->assertionManager->setHandler('resetFunction', function (test\adapter\invoker $invoker) use($phpMocker) {
         $phpMocker->resetCalls($invoker->getFunction());
         return $invoker;
     });
     $assertionAliaser = $this->assertionManager->getAliaser();
     $this->assertionManager->setPropertyHandler('define', function () use($assertionAliaser, $test) {
         return $assertionAliaser;
     })->setHandler('from', function ($class) use($assertionAliaser, $test) {
         $assertionAliaser->from($class);
         return $test;
     })->setHandler('use', function ($target) use($assertionAliaser, $test) {
         $assertionAliaser->alias($target);
         return $test;
     })->setHandler('as', function ($alias) use($assertionAliaser, $test) {
         $assertionAliaser->to($alias);
         return $test;
     });
     $asserterGenerator = $this->asserterGenerator;
     $this->assertionManager->setDefaultHandler(function ($keyword, $arguments) use($asserterGenerator, $assertionAliaser, &$lastAsserter) {
         static $lastAsserter = null;
         if ($lastAsserter !== null) {
             $realKeyword = $assertionAliaser->resolveAlias($keyword, get_class($lastAsserter));
             if ($realKeyword !== $keyword) {
                 return call_user_func_array(array($lastAsserter, $realKeyword), $arguments);
             }
         }
         return $lastAsserter = $asserterGenerator->getAsserterInstance($keyword, $arguments);
     });
     $this->assertionManager->use('phpArray')->as('array')->use('phpArray')->as('in')->use('phpClass')->as('class')->use('phpFunction')->as('function')->use('phpFloat')->as('float')->use('phpString')->as('string')->use('calling')->as('method');
     return $this;
 }
예제 #5
0
 public function setAssertionManager(test\assertion\manager $assertionManager = null)
 {
     $this->assertionManager = $assertionManager ?: new test\assertion\manager();
     $test = $this;
     $this->assertionManager->setHandler('when', function ($mixed) use($test) {
         if ($mixed instanceof \closure) {
             $mixed();
         }
         return $test;
     })->setHandler('assert', function ($case = null) use($test) {
         $test->stopCase();
         if ($case !== null) {
             $test->startCase($case);
         }
         return $test;
     })->setHandler('mockGenerator', function () use($test) {
         return $test->getMockGenerator();
     })->setHandler('mockClass', function ($class, $mockNamespace = null, $mockClass = null) use($test) {
         $test->getMockGenerator()->generate($class, $mockNamespace, $mockClass);
         return $test;
     })->setHandler('mockTestedClass', function ($mockNamespace = null, $mockClass = null) use($test) {
         $test->getMockGenerator()->generate($test->getTestedClassName(), $mockNamespace, $mockClass);
         return $test;
     })->setHandler('dump', function () use($test) {
         if ($test->debugModeIsEnabled() === true) {
             call_user_func_array('var_dump', func_get_args());
         }
         return $test;
     })->setHandler('stop', function () use($test) {
         if ($test->debugModeIsEnabled() === true) {
             throw new test\exceptions\stop();
         }
         return $test;
     })->setHandler('executeOnFailure', function ($callback) use($test) {
         if ($test->debugModeIsEnabled() === true) {
             $test->executeOnFailure($callback);
         }
         return $test;
     })->setHandler('dumpOnFailure', function ($variable) use($test) {
         if ($test->debugModeIsEnabled() === true) {
             $test->executeOnFailure(function () use($variable) {
                 var_dump($variable);
             });
         }
         return $test;
     })->setPropertyHandler('function', function () use($test) {
         return $test->getPhpMocker();
     })->setPropertyHandler('exception', function () {
         return asserters\exception::getLastValue();
     });
     $mockGenerator = $this->mockGenerator;
     $this->assertionManager->setPropertyHandler('nextMockedMethod', function () use($mockGenerator) {
         return $mockGenerator->getMethod();
     });
     $returnTest = function () use($test) {
         return $test;
     };
     $this->assertionManager->setHandler('if', $returnTest)->setHandler('and', $returnTest)->setHandler('then', $returnTest)->setHandler('given', $returnTest);
     $returnMockController = function (mock\aggregator $mock) {
         return $mock->getMockController();
     };
     $this->assertionManager->setHandler('calling', $returnMockController)->setHandler('ƒ', $returnMockController)->setHandler('resetMock', function (mock\aggregator $mock) {
         return $mock->getMockController()->resetCalls();
     })->setHandler('resetFunction', function (test\adapter\invoker $invoker) {
         php\mocker::getAdapter()->resetCalls($invoker->getFunction());
         return $invoker;
     });
     $this->assertionManager->setHandler('resetAdapter', function (test\adapter $adapter) {
         return $adapter->resetCalls();
     });
     $asserterGenerator = $this->asserterGenerator;
     $this->assertionManager->setHandler('define', function () use($asserterGenerator) {
         return $asserterGenerator;
     })->setDefaultHandler(function ($asserter, $arguments) use($asserterGenerator) {
         return $asserterGenerator->getAsserterInstance($asserter, $arguments);
     });
     return $this;
 }
예제 #6
0
 public function testGetLastValue()
 {
     $this->variable(asserters\exception::getLastValue())->isNull()->if($this->newTestedInstance->setWith(function () use(&$exception) {
         $exception = new \exception();
         throw $exception;
     }))->then->object(asserters\exception::getLastValue())->isIdenticalTo($exception)->if($this->testedInstance->setWith(function () use(&$otherException) {
         $otherException = new \exception();
         throw $otherException;
     }))->then->object(asserters\exception::getLastValue())->isIdenticalTo($otherException);
 }
예제 #7
0
 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();
 }