Best Atoum code snippet using manager.setHandler
test.php
Source:test.php
...104 $annotationExtractor->extract($class->getDocComment());105 if ($this->testNamespace === null || $this->testMethodPrefix === null)106 {107 $annotationExtractor108 ->unsetHandler('ignore')109 ->unsetHandler('tags')110 ->unsetHandler('maxChildrenNumber')111 ;112 $parentClass = $class;113 while (($this->testNamespace === null || $this->testMethodPrefix === null) && ($parentClass = $parentClass->getParentClass()) !== false)114 {115 $annotationExtractor->extract($parentClass->getDocComment());116 if ($this->testNamespace !== null)117 {118 $annotationExtractor->unsetHandler('namespace');119 }120 if ($this->testMethodPrefix !== null)121 {122 $annotationExtractor->unsetHandler('methodPrefix');123 }124 }125 }126 $this->setMethodAnnotations($annotationExtractor, $methodName);127 $testMethodPrefix = $this->getTestMethodPrefix();128 if (static::isRegex($testMethodPrefix) === false)129 {130 $testMethodFilter = function($methodName) use ($testMethodPrefix) { return (stripos($methodName, $testMethodPrefix) === 0); };131 }132 else133 {134 $testMethodFilter = function($methodName) use ($testMethodPrefix) { return (preg_match($testMethodPrefix, $methodName) == true); };135 }136 foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $publicMethod)137 {138 $methodName = $publicMethod->getName();139 if ($testMethodFilter($methodName) == true)140 {141 $this->testMethods[$methodName] = array();142 $annotationExtractor->extract($publicMethod->getDocComment());143 if ($publicMethod->getNumberOfParameters() > 0 && isset($this->dataProviders[$methodName]) === false)144 {145 $this->setDataProvider($methodName);146 }147 }148 }149 $this->runTestMethods($this->getTestMethods());150 }151 public function __toString()152 {153 return $this->getClass();154 }155 public function __get($property)156 {157 return $this->assertionManager->__get($property);158 }159 public function __set($property, $handler)160 {161 $this->assertionManager->{$property} = $handler;162 return $this;163 }164 public function __call($method, array $arguments)165 {166 return $this->assertionManager->__call($method, $arguments);167 }168 public function setTestAdapterStorage(test\adapter\storage $storage = null)169 {170 $this->testAdapterStorage = $storage ?: new test\adapter\storage();171 return $this;172 }173 public function getTestAdapterStorage()174 {175 return $this->testAdapterStorage;176 }177 public function setMockControllerLinker(mock\controller\linker $linker = null)178 {179 $this->mockControllerLinker = $linker ?: new mock\controller\linker();180 return $this;181 }182 public function getMockControllerLinker()183 {184 return $this->mockControllerLinker;185 }186 public function setScore(test\score $score = null)187 {188 $this->score = $score ?: new test\score();189 return $this;190 }191 public function getScore()192 {193 return $this->score;194 }195 public function setLocale(locale $locale = null)196 {197 $this->locale = $locale ?: new locale();198 return $this;199 }200 public function getLocale()201 {202 return $this->locale;203 }204 public function setAdapter(adapter $adapter = null)205 {206 $this->adapter = $adapter ?: new adapter();207 return $this;208 }209 public function getAdapter()210 {211 return $this->adapter;212 }213 public function setPhpMocker(php\mocker $phpMocker = null)214 {215 $this->phpMocker = $phpMocker ?: new php\mocker();216 return $this;217 }218 public function getPhpMocker()219 {220 return $this->phpMocker;221 }222 public function setMockGenerator(test\mock\generator $generator = null)223 {224 if ($generator !== null)225 {226 $generator->setTest($this);227 }228 else229 {230 $generator = new test\mock\generator($this);231 }232 $this->mockGenerator = $generator;233 return $this;234 }235 public function getMockGenerator()236 {237 return $this->mockGenerator;238 }239 public function setFactoryBuilder(factory\builder $factoryBuilder = null)240 {241 $this->factoryBuilder = $factoryBuilder ?: new factory\builder\closure();242 return $this;243 }244 public function getFactoryBuilder()245 {246 return $this->factoryBuilder;247 }248 public function setReflectionMethodFactory(\closure $factory = null)249 {250 $this->reflectionMethodFactory = $factory ?: function($class, $method) { return new \reflectionMethod($class, $method); };251 return $this;252 }253 public function setAsserterGenerator(test\asserter\generator $generator = null)254 {255 if ($generator !== null)256 {257 $generator->setTest($this);258 }259 else260 {261 $generator = new test\asserter\generator($this);262 }263 $this->asserterGenerator = $generator->setTest($this);264 return $this;265 }266 public function getAsserterGenerator()267 {268 $this->testAdapterStorage->resetCalls();269 return $this->asserterGenerator;270 }271 public function setAssertionManager(test\assertion\manager $assertionManager = null)272 {273 $this->assertionManager = $assertionManager ?: new test\assertion\manager();274 $test = $this;275 $this->assertionManager276 ->setHandler('when', function($mixed) use ($test) { if ($mixed instanceof \closure) { $mixed(); } return $test; })277 ->setHandler('assert', function($case = null) use ($test) { $test->stopCase(); if ($case !== null) { $test->startCase($case); } return $test; })278 ->setHandler('mockGenerator', function() use ($test) { return $test->getMockGenerator(); })279 ->setHandler('mockClass', function($class, $mockNamespace = null, $mockClass = null) use ($test) { $test->getMockGenerator()->generate($class, $mockNamespace, $mockClass); return $test; })280 ->setHandler('mockTestedClass', function($mockNamespace = null, $mockClass = null) use ($test) { $test->getMockGenerator()->generate($test->getTestedClassName(), $mockNamespace, $mockClass); return $test; })281 ->setHandler('dump', function() use ($test) { if ($test->debugModeIsEnabled() === true) { call_user_func_array('var_dump', func_get_args()); } return $test; })282 ->setHandler('stop', function() use ($test) { if ($test->debugModeIsEnabled() === true) { throw new test\exceptions\stop(); } return $test; })283 ->setHandler('executeOnFailure', function($callback) use ($test) { if ($test->debugModeIsEnabled() === true) { $test->executeOnFailure($callback); } return $test; })284 ->setHandler('dumpOnFailure', function($variable) use ($test) { if ($test->debugModeIsEnabled() === true) { $test->executeOnFailure(function() use ($variable) { var_dump($variable); }); } return $test; })285 ->setPropertyHandler('function', function() use ($test) { return $test->getPhpMocker(); })286 ->setPropertyHandler('exception', function() { return asserters\exception::getLastValue(); })287 ;288 $mockGenerator = $this->mockGenerator;289 $this->assertionManager290 ->setPropertyHandler('nextMockedMethod', function() use ($mockGenerator) { return $mockGenerator->getMethod(); })291 ;292 $returnTest = function() use ($test) { return $test; };293 $this->assertionManager294 ->setHandler('if', $returnTest)295 ->setHandler('and', $returnTest)296 ->setHandler('then', $returnTest)297 ->setHandler('given', $returnTest)298 ->setMethodHandler('define', $returnTest)299 ;300 $returnMockController = function(mock\aggregator $mock) { return $mock->getMockController(); };301 $this->assertionManager302 ->setHandler('calling', $returnMockController)303 ->setHandler('Æ', $returnMockController)304 ;305 $this->assertionManager306 ->setHandler('resetMock', function(mock\aggregator $mock) { return $mock->getMockController()->resetCalls(); })307 ->setHandler('resetAdapter', function(test\adapter $adapter) { return $adapter->resetCalls(); })308 ;309 $phpMocker = $this->phpMocker;310 $this->assertionManager->setHandler('resetFunction', function(test\adapter\invoker $invoker) use ($phpMocker) { $phpMocker->resetCalls($invoker->getFunction()); return $invoker; });311 $assertionAliaser = $this->assertionManager->getAliaser();312 $this->assertionManager313 ->setPropertyHandler('define', function() use ($assertionAliaser, $test) { return $assertionAliaser; })314 ->setHandler('from', function($class) use ($assertionAliaser, $test) { $assertionAliaser->from($class); return $test; })315 ->setHandler('use', function($target) use ($assertionAliaser, $test) { $assertionAliaser->alias($target); return $test; })316 ->setHandler('as', function($alias) use ($assertionAliaser, $test) { $assertionAliaser->to($alias); return $test; })317 ;318 $asserterGenerator = $this->asserterGenerator;319 $this->assertionManager->setDefaultHandler(function($keyword, $arguments) use ($asserterGenerator, $assertionAliaser, & $lastAsserter) {320 static $lastAsserter = null;321 if ($lastAsserter !== null)322 {323 $realKeyword = $assertionAliaser->resolveAlias($keyword, get_class($lastAsserter));324 if ($realKeyword !== $keyword)325 {326 return call_user_func_array(array($lastAsserter, $realKeyword), $arguments);327 }328 }329 return ($lastAsserter = $asserterGenerator->getAsserterInstance($keyword, $arguments));330 }331 );332 $this->assertionManager333 ->use('phpArray')->as('array')334 ->use('phpArray')->as('in')335 ->use('phpClass')->as('class')336 ->use('phpFunction')->as('function')337 ->use('calling')->as('method')338 ;339 return $this;340 }341 public function getAsserterCallManager()342 {343 return $this->asserterCallManager;344 }345 public function setAsserterCallManager(asserters\adapter\call\manager $asserterCallManager = null)346 {347 $this->asserterCallManager = $asserterCallManager ?: new asserters\adapter\call\manager();348 return $this;349 }350 public function addClassPhpVersion($version, $operator = null)351 {352 $this->phpVersions[$version] = $operator ?: '>=';353 return $this;354 }355 public function getClassPhpVersions()356 {357 return $this->phpVersions;358 }359 public function addMandatoryClassExtension($extension)360 {361 $this->mandatoryExtensions[] = $extension;362 return $this;363 }364 public function addMethodPhpVersion($testMethodName, $version, $operator = null)365 {366 $this->checkMethod($testMethodName)->testMethods[$testMethodName]['php'][$version] = $operator ?: '>=';367 return $this;368 }369 public function getMethodPhpVersions($testMethodName = null)370 {371 $versions = array();372 $classVersions = $this->getClassPhpVersions();373 if ($testMethodName === null)374 {375 foreach ($this->testMethods as $testMethodName => $annotations)376 {377 if (isset($annotations['php']) === false)378 {379 $versions[$testMethodName] = $classVersions;380 }381 else382 {383 $versions[$testMethodName] = array_merge($classVersions, $annotations['php']);384 }385 }386 }387 else388 {389 if (isset($this->checkMethod($testMethodName)->testMethods[$testMethodName]['php']) === false)390 {391 $versions = $classVersions;392 }393 else394 {395 $versions = array_merge($classVersions, $this->testMethods[$testMethodName]['php']);396 }397 }398 return $versions;399 }400 public function getMandatoryClassExtensions()401 {402 return $this->mandatoryExtensions;403 }404 public function addMandatoryMethodExtension($testMethodName, $extension)405 {406 $this->checkMethod($testMethodName)->testMethods[$testMethodName]['mandatoryExtensions'][] = $extension;407 return $this;408 }409 public function getMandatoryMethodExtensions($testMethodName = null)410 {411 $extensions = array();412 $mandatoryClassExtensions = $this->getMandatoryClassExtensions();413 if ($testMethodName === null)414 {415 foreach ($this->testMethods as $testMethodName => $annotations)416 {417 if (isset($annotations['mandatoryExtensions']) === false)418 {419 $extensions[$testMethodName] = $mandatoryClassExtensions;420 }421 else422 {423 $extensions[$testMethodName] = array_merge($mandatoryClassExtensions, $annotations['mandatoryExtensions']);424 }425 }426 }427 else428 {429 if (isset($this->checkMethod($testMethodName)->testMethods[$testMethodName]['mandatoryExtensions']) === false)430 {431 $extensions = $mandatoryClassExtensions;432 }433 else434 {435 $extensions = array_merge($mandatoryClassExtensions, $this->testMethods[$testMethodName]['mandatoryExtensions']);436 }437 }438 return $extensions;439 }440 public function skip($message)441 {442 throw new test\exceptions\skip($message);443 }444 public function getAssertionManager()445 {446 return $this->assertionManager;447 }448 public function setClassEngine($engine)449 {450 $this->classEngine = (string) $engine;451 return $this;452 }453 public function getClassEngine()454 {455 return $this->classEngine;456 }457 public function classHasVoidMethods()458 {459 $this->classHasNotVoidMethods = false;460 }461 public function classHasNotVoidMethods()462 {463 $this->classHasNotVoidMethods = true;464 }465 public function setMethodVoid($method)466 {467 $this->methodsAreNotVoid[$method] = false;468 }469 public function setMethodNotVoid($method)470 {471 $this->methodsAreNotVoid[$method] = true;472 }473 public function methodIsNotVoid($method)474 {475 return (isset($this->methodsAreNotVoid[$method]) === false ? $this->classHasNotVoidMethods : $this->methodsAreNotVoid[$method]);476 }477 public function setMethodEngine($method, $engine)478 {479 $this->methodEngines[(string) $method] = (string) $engine;480 return $this;481 }482 public function getMethodEngine($method)483 {484 $method = (string) $method;485 return (isset($this->methodEngines[$method]) === false ? null : $this->methodEngines[$method]);486 }487 public function enableDebugMode()488 {489 $this->debugMode = true;490 return $this;491 }492 public function disableDebugMode()493 {494 $this->debugMode = false;495 return $this;496 }497 public function debugModeIsEnabled()498 {499 return $this->debugMode;500 }501 public function setXdebugConfig($value)502 {503 $this->xdebugConfig = $value;504 return $this;505 }506 public function getXdebugConfig()507 {508 return $this->xdebugConfig;509 }510 public function executeOnFailure(\closure $closure)511 {512 $this->executeOnFailure[] = $closure;513 return $this;514 }515 public function codeCoverageIsEnabled()516 {517 return $this->codeCoverage;518 }519 public function enableCodeCoverage()520 {521 $this->codeCoverage = $this->adapter->extension_loaded('xdebug');522 return $this;523 }524 public function disableCodeCoverage()525 {526 $this->codeCoverage = false;527 return $this;528 }529 public function setMaxChildrenNumber($number)530 {531 $number = (int) $number;532 if ($number < 1)533 {534 throw new exceptions\logic\invalidArgument('Maximum number of children must be greater or equal to 1');535 }536 $this->maxAsynchronousEngines = $number;537 return $this;538 }539 public function setBootstrapFile($path)540 {541 $this->bootstrapFile = $path;542 return $this;543 }544 public function getBootstrapFile()545 {546 return $this->bootstrapFile;547 }548 public function setTestNamespace($testNamespace)549 {550 $this->testNamespace = self::cleanNamespace($testNamespace);551 if ($this->testNamespace === '')552 {553 throw new exceptions\logic\invalidArgument('Test namespace must not be empty');554 }555 return $this;556 }557 public function getTestNamespace()558 {559 return $this->testNamespace ?: self::getNamespace();560 }561 public function setTestMethodPrefix($methodPrefix)562 {563 $methodPrefix = (string) $methodPrefix;564 if ($methodPrefix == '')565 {566 throw new exceptions\logic\invalidArgument('Test method prefix must not be empty');567 }568 $this->testMethodPrefix = $methodPrefix;569 return $this;570 }571 public function getTestMethodPrefix()572 {573 return $this->testMethodPrefix ?: self::getMethodPrefix();574 }575 public function setPhpPath($path)576 {577 $this->phpPath = (string) $path;578 return $this;579 }580 public function getPhpPath()581 {582 return $this->phpPath;583 }584 public function getAllTags()585 {586 $tags = $this->getTags();587 foreach ($this->testMethods as $annotations)588 {589 if (isset($annotations['tags']) === true)590 {591 $tags = array_merge($tags, array_diff($annotations['tags'], $tags));592 }593 }594 return array_values($tags);595 }596 public function setTags(array $tags)597 {598 $this->tags = $tags;599 return $this;600 }601 public function getTags()602 {603 return $this->tags;604 }605 public function setMethodTags($testMethodName, array $tags)606 {607 $this->checkMethod($testMethodName)->testMethods[$testMethodName]['tags'] = $tags;608 return $this;609 }610 public function getMethodTags($testMethodName = null)611 {612 $tags = array();613 $classTags = $this->getTags();614 if ($testMethodName === null)615 {616 foreach ($this->testMethods as $testMethodName => $annotations)617 {618 $tags[$testMethodName] = isset($annotations['tags']) === false ? $classTags : $annotations['tags'];619 }620 }621 else622 {623 $tags = isset($this->checkMethod($testMethodName)->testMethods[$testMethodName]['tags']) === false ? $classTags : $this->testMethods[$testMethodName]['tags'];624 }625 return $tags;626 }627 public function getDataProviders()628 {629 return $this->dataProviders;630 }631 public function getTestedClassName()632 {633 if ($this->testedClassName === null)634 {635 $this->testedClassName = self::getTestedClassNameFromTestClass($this->getClass(), $this->getTestNamespace());636 }637 return $this->testedClassName;638 }639 public function getTestedClassNamespace()640 {641 $testedClassName = $this->getTestedClassName();642 return substr($testedClassName, 0, strrpos($testedClassName, '\\'));643 }644 public function getTestedClassPath()645 {646 if ($this->testedClassPath === null)647 {648 $testedClass = new \reflectionClass($this->getTestedClassName());649 $this->testedClassPath = $testedClass->getFilename();650 }651 return $this->testedClassPath;652 }653 public function setTestedClassName($className)654 {655 if ($this->testedClassName !== null)656 {657 throw new exceptions\runtime('Tested class name is already defined');658 }659 $this->testedClassName = $className;660 return $this;661 }662 public function getClass()663 {664 return $this->class;665 }666 public function getClassNamespace()667 {668 return $this->classNamespace;669 }670 public function getPath()671 {672 return $this->path;673 }674 public function getTaggedTestMethods(array $methods, array $tags = array())675 {676 return array_values(array_uintersect($methods, $this->getTestMethods($tags), 'strcasecmp'));677 }678 public function getTestMethods(array $tags = array())679 {680 $testMethods = array();681 foreach (array_keys($this->testMethods) as $methodName)682 {683 if ($this->methodIsIgnored($methodName, $tags) === false)684 {685 $testMethods[] = $methodName;686 }687 }688 return $testMethods;689 }690 public function getCurrentMethod()691 {692 return $this->currentMethod;693 }694 public function getMaxChildrenNumber()695 {696 return $this->maxAsynchronousEngines;697 }698 public function getCoverage()699 {700 return $this->score->getCoverage();701 }702 public function count()703 {704 return sizeof($this->runTestMethods);705 }706 public function addObserver(observer $observer)707 {708 $this->observers[] = $observer;709 return $this;710 }711 public function callObservers($event)712 {713 foreach ($this->observers as $observer)714 {715 $observer->handleEvent($event, $this);716 }717 return $this;718 }719 public function ignore($boolean)720 {721 $this->ignore = ($boolean == true);722 return $this->runTestMethods($this->getTestMethods());723 }724 public function isIgnored(array $namespaces = array(), array $tags = array())725 {726 $isIgnored = (sizeof($this) <= 0 || $this->ignore === true);727 if ($isIgnored === false && sizeof($namespaces) > 0)728 {729 $classNamespace = strtolower($this->getClassNamespace());730 $isIgnored = sizeof(array_filter($namespaces, function($value) use ($classNamespace) { return strpos($classNamespace, strtolower($value)) === 0; })) <= 0;731 }732 if ($isIgnored === false && sizeof($tags) > 0)733 {734 $isIgnored = sizeof($testTags = $this->getAllTags()) <= 0 || sizeof(array_intersect($tags, $testTags)) == 0;735 }736 return $isIgnored;737 }738 public function ignoreMethod($methodName, $boolean)739 {740 $this->checkMethod($methodName)->testMethods[$methodName]['ignore'] = $boolean == true;741 return $this->runTestMethods($this->getTestMethods());742 }743 public function methodIsIgnored($methodName, array $tags = array())744 {745 $isIgnored = $this->checkMethod($methodName)->ignore;746 if ($isIgnored === false)747 {748 if (isset($this->testMethods[$methodName]['ignore']) === true)749 {750 $isIgnored = $this->testMethods[$methodName]['ignore'];751 }752 if ($isIgnored === false && $tags)753 {754 $isIgnored = sizeof($methodTags = $this->getMethodTags($methodName)) <= 0 || sizeof(array_intersect($tags, $methodTags)) <= 0;755 }756 }757 return $isIgnored;758 }759 public function runTestMethods(array $methods, array $tags = array())760 {761 $this->runTestMethods = $runTestMethods = array();762 if (isset($methods['*']) === true)763 {764 $runTestMethods = $methods['*'];765 }766 $testClass = $this->getClass();767 if (isset($methods[$testClass]) === true)768 {769 $runTestMethods = $methods[$testClass];770 }771 if (in_array('*', $runTestMethods) === true)772 {773 $runTestMethods = array();774 }775 if (sizeof($runTestMethods) <= 0)776 {777 $runTestMethods = $this->getTestMethods($tags);778 }779 else780 {781 $runTestMethods = $this->getTaggedTestMethods($runTestMethods, $tags);782 }783 foreach ($runTestMethods as $method)784 {785 if ($this->xdebugConfig != null)786 {787 $engineClass = 'mageekguy\atoum\test\engines\concurrent';788 }789 else790 {791 $engineName = $engineClass = ($this->getMethodEngine($method) ?: $this->getClassEngine() ?: self::getDefaultEngine());792 if (substr($engineClass, 0, 1) !== '\\')793 {794 $engineClass = self::enginesNamespace . '\\' . $engineClass;795 }796 if (class_exists($engineClass) === false)797 {798 throw new exceptions\runtime('Test engine \'' . $engineName . '\' does not exist for method \'' . $this->class . '::' . $method . '()\'');799 }800 }801 $engine = new $engineClass();802 if ($engine instanceof test\engine === false)803 {804 throw new exceptions\runtime('Test engine \'' . $engineName . '\' is invalid for method \'' . $this->class . '::' . $method . '()\'');805 }806 $this->runTestMethods[$method] = $engine;807 }808 return $this;809 }810 public function runTestMethod($testMethod, array $tags = array())811 {812 if ($this->methodIsIgnored($testMethod, $tags) === false)813 {814 $mockGenerator = $this->getMockGenerator();815 $mockNamespacePattern = '/^' . preg_quote($mockGenerator->getDefaultNamespace()) . '\\\/i';816 $mockAutoloader = function($class) use ($mockGenerator, $mockNamespacePattern) {817 $mockedClass = preg_replace($mockNamespacePattern, '', $class);818 if ($mockedClass !== $class)819 {820 $mockGenerator->generate($mockedClass);821 }822 };823 if (spl_autoload_register($mockAutoloader, true, true) === false)824 {825 throw new exceptions\runtime('Unable to register mock autoloader');826 }827 set_error_handler(array($this, 'errorHandler'));828 ini_set('display_errors', 'stderr');829 ini_set('log_errors', 'Off');830 ini_set('log_errors_max_len', '0');831 $this->currentMethod = $testMethod;832 $this->executeOnFailure = array();833 $this->phpMocker->setDefaultNamespace($this->getTestedClassNamespace());834 try835 {836 foreach ($this->getMethodPhpVersions($testMethod) as $phpVersion => $operator)837 {838 if (version_compare(phpversion(), $phpVersion, $operator) === false)839 {840 throw new test\exceptions\skip('PHP version ' . PHP_VERSION . ' is not ' . $operator . ' to ' . $phpVersion);841 }842 }843 foreach ($this->getMandatoryMethodExtensions($testMethod) as $mandatoryExtension)844 {845 $this->extension($mandatoryExtension)->isLoaded();846 }847 try848 {849 ob_start();850 try851 {852 $testedClass = new \reflectionClass($testedClassName = $this->getTestedClassName());853 }854 catch (\exception $exception)855 {856 throw new exceptions\runtime('Tested class \'' . $testedClassName . '\' does not exist for test class \'' . $this->getClass() . '\'');857 }858 if ($testedClass->isAbstract() === true)859 {860 $testedClass = new \reflectionClass($testedClassName = $mockGenerator->getDefaultNamespace() . '\\' . $testedClassName);861 }862 $this->factoryBuilder->build($testedClass, $instance)863 ->addToAssertionManager($this->assertionManager, 'newTestedInstance', function() use ($testedClass) {864 throw new exceptions\runtime('Tested class ' . $testedClass->getName() . ' has no constructor or its constructor has at least one mandatory argument');865 }866 )867 ;868 $this->factoryBuilder->build($testedClass)869 ->addToAssertionManager($this->assertionManager, 'newInstance', function() use ($testedClass) {870 throw new exceptions\runtime('Tested class ' . $testedClass->getName() . ' has no constructor or its constructor has at least one mandatory argument');871 }872 )873 ;874 $this->assertionManager->setPropertyHandler('testedInstance', function() use (& $instance) {875 if ($instance === null)876 {877 throw new exceptions\runtime('Use $this->newTestedInstance before using $this->testedInstance');878 }879 return $instance;880 }881 );882 test\adapter::setStorage($this->testAdapterStorage);883 mock\controller::setLinker($this->mockControllerLinker);884 $this->testAdapterStorage->add(php\mocker::getAdapter());885 $this->beforeTestMethod($this->currentMethod);886 if ($this->codeCoverageIsEnabled() === true)887 {888 xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);889 }890 $assertionNumber = $this->score->getAssertionNumber();891 $time = microtime(true);892 $memory = memory_get_usage(true);893 if (isset($this->dataProviders[$testMethod]) === false)894 {895 $this->{$testMethod}();896 $this->asserterCallManager->check();897 }898 else899 {900 $data = $this->{$this->dataProviders[$testMethod]}();901 if (is_array($data) === false && $data instanceof \traversable === false)902 {903 throw new test\exceptions\runtime('Data provider ' . $this->getClass() . '::' . $this->dataProviders[$testMethod] . '() must return an array or an iterator');904 }905 $reflectedTestMethod = call_user_func($this->reflectionMethodFactory, $this, $testMethod);906 $numberOfArguments = $reflectedTestMethod->getNumberOfRequiredParameters();907 foreach ($data as $key => $arguments)908 {909 if (is_array($arguments) === false)910 {911 $arguments = array($arguments);912 }913 if (sizeof($arguments) != $numberOfArguments)914 {915 throw new test\exceptions\runtime('Data provider ' . $this->getClass() . '::' . $this->dataProviders[$testMethod] . '() not provide enough arguments at key ' . $key . ' for test method ' . $this->getClass() . '::' . $testMethod . '()');916 }917 $this->score->setDataSet($key, $this->dataProviders[$testMethod]);918 $reflectedTestMethod->invokeArgs($this, $arguments);919 $this->asserterCallManager->check();920 $this->score->unsetDataSet();921 }922 }923 $this->mockControllerLinker->reset();924 $this->testAdapterStorage->reset();925 $memoryUsage = memory_get_usage(true) - $memory;926 $duration = microtime(true) - $time;927 $this->score928 ->addMemoryUsage($this->path, $this->class, $this->currentMethod, $memoryUsage)929 ->addDuration($this->path, $this->class, $this->currentMethod, $duration)930 ->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean())931 ;932 if ($this->codeCoverageIsEnabled() === true)933 {934 $this->score->getCoverage()->addXdebugDataForTest($this, xdebug_get_code_coverage());935 xdebug_stop_code_coverage();936 }937 if ($assertionNumber == $this->score->getAssertionNumber() && $this->methodIsNotVoid($this->currentMethod) === false)938 {939 $this->score->addVoidMethod($this->path, $this->class, $this->currentMethod);940 }941 }942 catch (\exception $exception)943 {944 $this->score->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean());945 throw $exception;946 }947 }948 catch (asserter\exception $exception)949 {950 foreach ($this->executeOnFailure as $closure)951 {952 ob_start();953 $closure();954 $this->score->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean());955 }956 if ($this->score->failExists($exception) === false)957 {958 $this->addExceptionToScore($exception);959 }960 }961 catch (test\exceptions\runtime $exception)962 {963 $this->score->addRuntimeException($this->path, $this->class, $this->currentMethod, $exception);964 }965 catch (test\exceptions\skip $exception)966 {967 list($file, $line) = $this->getBacktrace($exception->getTrace());968 $this->score->addSkippedMethod($file, $this->class, $this->currentMethod, $line, $exception->getMessage());969 }970 catch (test\exceptions\stop $exception)971 {972 }973 catch (exception $exception)974 {975 list($file, $line) = $this->getBacktrace($exception->getTrace());976 $this->errorHandler(E_USER_ERROR, $exception->getMessage(), $file, $line);977 }978 catch (\exception $exception)979 {980 $this->addExceptionToScore($exception);981 }982 $this->afterTestMethod($this->currentMethod);983 $this->currentMethod = null;984 restore_error_handler();985 ini_restore('display_errors');986 ini_restore('log_errors');987 ini_restore('log_errors_max_len');988 if (spl_autoload_unregister($mockAutoloader) === false)989 {990 throw new \runtimeException('Unable to unregister mock autoloader');991 }992 }993 return $this;994 }995 public function run(array $runTestMethods = array(), array $tags = array())996 {997 if ($runTestMethods)998 {999 $this->runTestMethods(array_intersect($runTestMethods, $this->getTestMethods($tags)));1000 }1001 if ($this->isIgnored() === false)1002 {1003 $this->callObservers(self::runStart);1004 try1005 {1006 $this->runEngines();1007 }1008 catch (\exception $exception)1009 {1010 $this->stopEngines();1011 throw $exception;1012 }1013 $this->callObservers(self::runStop);1014 }1015 return $this;1016 }1017 public function startCase($case)1018 {1019 $this->testAdapterStorage->resetCalls();1020 $this->score->setCase($case);1021 return $this;1022 }1023 public function stopCase()1024 {1025 $this->testAdapterStorage->resetCalls();1026 $this->score->unsetCase();1027 return $this;1028 }1029 public function setDataProvider($testMethodName, $dataProvider = null)1030 {1031 if ($dataProvider === null)1032 {1033 $dataProvider = $testMethodName . 'DataProvider';1034 }1035 if (method_exists($this->checkMethod($testMethodName), $dataProvider) === false)1036 {1037 throw new exceptions\logic\invalidArgument('Data provider ' . $this->class . '::' . lcfirst($dataProvider) . '() is unknown');1038 }1039 $this->dataProviders[$testMethodName] = $dataProvider;1040 return $this;1041 }1042 public function errorHandler($errno, $errstr, $errfile, $errline)1043 {1044 $doNotCallDefaultErrorHandler = true;1045 $errorReporting = $this->adapter->error_reporting();1046 if ($errorReporting !== 0 && $errorReporting & $errno)1047 {1048 list($file, $line) = $this->getBacktrace();1049 $this->score->addError($file ?: ($errfile ?: $this->path), $this->class, $this->currentMethod, $line ?: $errline, $errno, trim($errstr), $errfile, $errline);1050 $doNotCallDefaultErrorHandler = !($errno & E_RECOVERABLE_ERROR);1051 }1052 return $doNotCallDefaultErrorHandler;1053 }1054 public function setUp() {}1055 public function beforeTestMethod($testMethod) {}1056 public function afterTestMethod($testMethod) {}1057 public function tearDown() {}1058 public static function setNamespace($namespace)1059 {1060 $namespace = self::cleanNamespace($namespace);1061 if ($namespace === '')1062 {1063 throw new exceptions\logic\invalidArgument('Namespace must not be empty');1064 }1065 self::$namespace = $namespace;1066 }1067 public static function getNamespace()1068 {1069 return self::$namespace ?: self::defaultNamespace;1070 }1071 public static function setMethodPrefix($methodPrefix)1072 {1073 if ($methodPrefix == '')1074 {1075 throw new exceptions\logic\invalidArgument('Method prefix must not be empty');1076 }1077 self::$methodPrefix = $methodPrefix;1078 }1079 public static function getMethodPrefix()1080 {1081 return self::$methodPrefix ?: self::defaultMethodPrefix;1082 }1083 public static function setDefaultEngine($defaultEngine)1084 {1085 self::$defaultEngine = (string) $defaultEngine;1086 }1087 public static function getDefaultEngine()1088 {1089 return self::$defaultEngine ?: self::defaultEngine;1090 }1091 public static function getTestedClassNameFromTestClass($fullyQualifiedClassName, $testNamespace = null)1092 {1093 if ($testNamespace === null)1094 {1095 $testNamespace = self::getNamespace();1096 }1097 if (self::isRegex($testNamespace) === true)1098 {1099 if (preg_match($testNamespace, $fullyQualifiedClassName) === 0)1100 {1101 throw new exceptions\runtime('Test class \'' . $fullyQualifiedClassName . '\' is not in a namespace which match pattern \'' . $testNamespace . '\'');1102 }1103 $testedClassName = preg_replace($testNamespace, '\\', $fullyQualifiedClassName);1104 }1105 else1106 {1107 $position = strpos($fullyQualifiedClassName, $testNamespace);1108 if ($position === false)1109 {1110 throw new exceptions\runtime('Test class \'' . $fullyQualifiedClassName . '\' is not in a namespace which contains \'' . $testNamespace . '\'');1111 }1112 $testedClassName = substr($fullyQualifiedClassName, 0, $position) . substr($fullyQualifiedClassName, $position + 1 + strlen($testNamespace));1113 }1114 return trim($testedClassName, '\\');1115 }1116 protected function setClassAnnotations(annotations\extractor $extractor)1117 {1118 $test = $this;1119 $extractor1120 ->resetHandlers()1121 ->setHandler('ignore', function($value) use ($test) { $test->ignore(annotations\extractor::toBoolean($value)); })1122 ->setHandler('tags', function($value) use ($test) { $test->setTags(annotations\extractor::toArray($value)); })1123 ->setHandler('namespace', function($value) use ($test) { $test->setTestNamespace($value === true ? static::defaultNamespace : $value); })1124 ->setHandler('methodPrefix', function($value) use ($test) { $test->setTestMethodPrefix($value === true ? static::defaultMethodPrefix : $value); })1125 ->setHandler('maxChildrenNumber', function($value) use ($test) { $test->setMaxChildrenNumber($value); })1126 ->setHandler('engine', function($value) use ($test) { $test->setClassEngine($value); })1127 ->setHandler('hasVoidMethods', function($value) use ($test) { $test->classHasVoidMethods(); })1128 ->setHandler('hasNotVoidMethods', function($value) use ($test) { $test->classHasNotVoidMethods(); })1129 ->setHandler('php', function($value) use ($test) {1130 $value = annotations\extractor::toArray($value);1131 if (isset($value[0]) === true)1132 {1133 $operator = null;1134 if (isset($value[1]) === false)1135 {1136 $version = $value[0];1137 }1138 else1139 {1140 $version = $value[1];1141 switch ($value[0])1142 {1143 case '<':1144 case '<=':1145 case '=':1146 case '==':1147 case '>=':1148 case '>':1149 $operator = $value[0];1150 }1151 }1152 $test->addClassPhpVersion($version, $operator);1153 }1154 }1155 )1156 ->setHandler('extensions', function($value) use ($test) {1157 foreach (annotations\extractor::toArray($value) as $mandatoryExtension)1158 {1159 $test->addMandatoryClassExtension($mandatoryExtension);1160 }1161 }1162 )1163 ;1164 return $this;1165 }1166 protected function setMethodAnnotations(annotations\extractor $extractor, & $methodName)1167 {1168 $test = $this;1169 $extractor1170 ->resetHandlers()1171 ->setHandler('ignore', function($value) use ($test, & $methodName) { $test->ignoreMethod($methodName, annotations\extractor::toBoolean($value)); })1172 ->setHandler('tags', function($value) use ($test, & $methodName) { $test->setMethodTags($methodName, annotations\extractor::toArray($value)); })1173 ->setHandler('dataProvider', function($value) use ($test, & $methodName) { $test->setDataProvider($methodName, $value === true ? null : $value); })1174 ->setHandler('engine', function($value) use ($test, & $methodName) { $test->setMethodEngine($methodName, $value); })1175 ->setHandler('isVoid', function($value) use ($test, & $methodName) { $test->setMethodVoid($methodName); })1176 ->setHandler('isNotVoid', function($value) use ($test, & $methodName) { $test->setMethodNotVoid($methodName); })1177 ->setHandler('php', function($value) use ($test, & $methodName) {1178 $value = annotations\extractor::toArray($value);1179 if (isset($value[0]) === true)1180 {1181 $operator = null;1182 if (isset($value[1]) === false)1183 {1184 $version = $value[0];1185 }1186 else1187 {1188 $version = $value[1];1189 switch ($value[0])1190 {1191 case '<':1192 case '<=':1193 case '=':1194 case '==':1195 case '>=':1196 case '>':1197 $operator = $value[0];1198 }1199 }1200 $test->addMethodPhpVersion($methodName, $version, $operator);1201 }1202 }1203 )1204 ->setHandler('extensions', function($value) use ($test, & $methodName) {1205 foreach (annotations\extractor::toArray($value) as $mandatoryExtension)1206 {1207 $test->addMandatoryMethodExtension($methodName, $mandatoryExtension);1208 }1209 }1210 )1211 ;1212 return $this;1213 }1214 protected function getBacktrace(array $trace = null)1215 {1216 $debugBacktrace = $trace === null ? debug_backtrace(false) : $trace;1217 foreach ($debugBacktrace as $key => $value)1218 {...
manager.php
Source:manager.php
...30 ->hasMessage('There is no handler defined for event \'' . $event . '\'')31 ->if($assertionManager->setDefaultHandler(function() use (& $defaultReturn) { return ($defaultReturn = uniqid()); }))32 ->then33 ->string($assertionManager->{uniqid()})->isEqualTo($defaultReturn)34 ->if($assertionManager->setHandler($event = uniqid(), function() use (& $eventReturn) { return ($eventReturn = uniqid()); }))35 ->then36 ->string($assertionManager->{$event})->isEqualTo($eventReturn)37 ;38 }39 public function test__call()40 {41 $this42 ->if($assertionManager = new testedClass())43 ->then44 ->exception(function() use ($assertionManager, & $event) {45 $assertionManager->{$event = uniqid()}();46 }47 )48 ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')49 ->hasMessage('There is no handler defined for event \'' . $event . '\'')50 ->if($assertionManager->setDefaultHandler(function($event, $defaultArg) { return $defaultArg; }))51 ->then52 ->array($assertionManager->{$event = uniqid()}($arg = uniqid()))->isEqualTo(array($arg))53 ->if($assertionManager->setHandler($event, function($arg) { return $arg; }))54 ->then55 ->string($assertionManager->{$event}($eventArg = uniqid()))->isEqualTo($eventArg)56 ;57 }58 public function testSetHandler()59 {60 $this61 ->if($assertionManager = new testedClass())62 ->then63 ->object($assertionManager->setHandler($event = uniqid(), $handler = function() {}))->isIdenticalTo($assertionManager)64 ->array($assertionManager->getHandlers())->isEqualTo(array($event => $handler))65 ->object($assertionManager->setHandler($event, $otherHandler = function() {}))->isIdenticalTo($assertionManager)66 ->array($assertionManager->getHandlers())->isEqualTo(array($event => $otherHandler))67 ->object($assertionManager->setHandler($otherEvent = uniqid(), $handler))->isIdenticalTo($assertionManager)68 ->array($assertionManager->getHandlers())->isEqualTo(array($event => $otherHandler, $otherEvent => $handler))69 ;70 }71 public function testSetDefaultHandler()72 {73 $this74 ->if($assertionManager = new testedClass())75 ->then76 ->object($assertionManager->setDefaultHandler($handler = function() {}))->isIdenticalTo($assertionManager)77 ->object($assertionManager->getDefaultHandler())->isIdenticalTo($handler)78 ;79 }80 public function testInvoke()81 {82 $this83 ->if($assertionManager = new testedClass())84 ->then85 ->exception(function() use ($assertionManager, & $event) {86 $assertionManager->invoke($event = uniqid());87 }88 )89 ->isInstanceOf('mageekguy\atoum\test\assertion\manager\exception')90 ->hasMessage('There is no handler defined for event \'' . $event . '\'')91 ->if($assertionManager->setDefaultHandler(function($event, $arg) { return $arg; }))92 ->then93 ->array($assertionManager->invoke(uniqid(), array($defaultArg = uniqid())))->isEqualTo(array($defaultArg))94 ->if($assertionManager->setHandler($event = uniqid(), function($eventArg) { return $eventArg; }))95 ->then96 ->string($assertionManager->invoke($event, array($eventArg = uniqid())))->isEqualTo($eventArg)97 ;98 }99}...
setHandler
Using AI Code Generation
1require_once 'Zend/Loader.php';2Zend_Loader::loadClass('Zend_Controller_Front');3Zend_Loader::loadClass('Zend_Controller_Router_Rewrite');4$front = Zend_Controller_Front::getInstance();5$router = new Zend_Controller_Router_Rewrite();6$front->setRouter($router);7$router->addRoute('one', new Zend_Controller_Router_Route('one', array('controller' => 'one', 'action' => 'index')));8$router->addRoute('two', new Zend_Controller_Router_Route('two', array('controller' => 'two', 'action' => 'index')));9$front->setControllerDirectory('controllers');10$front->setParam('noViewRenderer', true);11$front->dispatch();12require_once 'Zend/Loader.php';13Zend_Loader::loadClass('Zend_Controller_Front');14$front = Zend_Controller_Front::getInstance();15$front->setControllerDirectory('controllers');16$front->setDefaultModule('default');17$front->setParam('noViewRenderer', true);18$front->dispatch();19require_once 'Zend/Loader.php';20Zend_Loader::loadClass('Zend_Controller_Front');21$front = Zend_Controller_Front::getInstance();22$front->setControllerDirectory('controllers');23$front->setDefaultModule('default');24$front->setDefaultControllerName('index');25$front->setParam('noViewRenderer', true);26$front->dispatch();27require_once 'Zend/Loader.php';28Zend_Loader::loadClass('Zend_Controller_Front');29$front = Zend_Controller_Front::getInstance();30$front->setControllerDirectory('controllers');31$front->setDefaultModule('default');32$front->setDefaultControllerName('index');33$front->setDefaultAction('index');34$front->setParam('noViewRenderer', true);35$front->dispatch();
setHandler
Using AI Code Generation
1$manager = new Manager();2$manager->setHandler('1.php');3$manager->run();4$manager = new Manager();5$manager->setHandler('2.php');6$manager->run();7$manager = new Manager();8$manager->setHandler('3.php');9$manager->run();10$manager = new Manager();11$manager->setHandler('4.php');12$manager->run();13$manager = new Manager();14$manager->setHandler('5.php');15$manager->run();16$manager = new Manager();17$manager->setHandler('6.php');18$manager->run();19$manager = new Manager();20$manager->setHandler('7.php');21$manager->run();22$manager = new Manager();23$manager->setHandler('8.php');24$manager->run();25$manager = new Manager();26$manager->setHandler('9.php');27$manager->run();28$manager = new Manager();29$manager->setHandler('10.php');30$manager->run();31$manager = new Manager();32$manager->setHandler('11.php');33$manager->run();34$manager = new Manager();35$manager->setHandler('12.php');36$manager->run();37$manager = new Manager();38$manager->setHandler('13.php');39$manager->run();
setHandler
Using AI Code Generation
1$manager->setHandler('1.php', '1.php');2$manager->setHandler('2.php', '2.php');3$manager->setHandler('3.php', '3.php');4$manager->setHandler('4.php', '4.php');5$manager->setHandler('5.php', '5.php');6$manager->setHandler('6.php', '6.php');7$manager->setHandler('7.php', '7.php');8$manager->setHandler('8.php', '8.php');9$manager->setHandler('9.php', '9.php');10$manager->setHandler('10.php', '10.php');11$manager->setHandler('11.php', '11.php');12$manager->setHandler('12.php', '12.php');13$manager->setHandler('13.php', '13.php');14$manager->setHandler('14.php', '14.php');15$manager->setHandler('15.php', '15.php');16$manager->setHandler('16.php', '16.php');
setHandler
Using AI Code Generation
1$manager = new Manager();2$manager->setHandler('1.php');3$manager->setHandler('2.php');4$manager->setHandler('3.php');5$manager->setHandler('4.php');6$manager->setHandler('5.php');7$manager->setHandler('6.php');8$manager->setHandler('7.php');9$manager->setHandler('8.php');10$manager->setHandler('9.php');11$manager->setHandler('10.php');12$manager->setHandler('11.php');13$manager->setHandler('12.php');14$manager->setHandler('13.php');15$manager->setHandler('14.php');16$manager->setHandler('15.php');17$manager->setHandler('16.php');18$manager->setHandler('17.php');19$manager->setHandler('18.php');20$manager->setHandler('19.php');21$manager->setHandler('20.php');22$manager->setHandler('21.php');23$manager->setHandler('22.php');24$manager->setHandler('23.php');25$manager->setHandler('24.php');26$manager->setHandler('25.php');27$manager->setHandler('26.php');28$manager->setHandler('27.php');29$manager->setHandler('28.php');30$manager->setHandler('29.php');31$manager->setHandler('30.php');32$manager->setHandler('31.php');33$manager->setHandler('32.php');34$manager->setHandler('33.php');35$manager->setHandler('34.php');36$manager->setHandler('35.php');37$manager->setHandler('36.php');38$manager->setHandler('37.php');39$manager->setHandler('38.php');40$manager->setHandler('39.php');41$manager->setHandler('40.php');42$manager->setHandler('41.php');43$manager->setHandler('42.php');44$manager->setHandler('43.php');45$manager->setHandler('44.php');46$manager->setHandler('45.php');47$manager->setHandler('46.php');48$manager->setHandler('47.php');49$manager->setHandler('48.php');50$manager->setHandler('49.php');51$manager->setHandler('50.php');52$manager->setHandler('51.php');53$manager->setHandler('52.php');54$manager->setHandler('53.php');55$manager->setHandler('54.php');56$manager->setHandler('
setHandler
Using AI Code Generation
1$manager = new Manager();2$manager->setHandler('1.php', '1.php');3$manager = new Manager();4$manager->getHandler('1.php');5$manager = new Manager();6$manager->removeHandler('1.php');7$manager = new Manager();8$manager->trigger('1.php');9$manager = new Manager();10$manager->getHandlerList();11$manager = new Manager();12$manager->getHandlerList();
setHandler
Using AI Code Generation
1require_once 'Manager.php';2$manager = new Manager();3$manager->setHandler('1');4echo $manager->getHandler();5require_once 'Manager.php';6$manager = new Manager();7$manager->setHandler('2');8echo $manager->getHandler();9require_once 'Manager.php';10$manager = new Manager();11$manager->setHandler('3');12echo $manager->getHandler();13require_once 'Manager.php';14$manager = new Manager();15$manager->setHandler('4');16echo $manager->getHandler();17require_once 'Manager.php';18$manager = new Manager();19$manager->setHandler('5');20echo $manager->getHandler();21require_once 'Manager.php';22$manager = new Manager();23$manager->setHandler('6');24echo $manager->getHandler();25require_once 'Manager.php';26$manager = new Manager();27$manager->setHandler('7');28echo $manager->getHandler();29require_once 'Manager.php';30$manager = new Manager();31$manager->setHandler('8');32echo $manager->getHandler();33require_once 'Manager.php';34$manager = new Manager();35$manager->setHandler('9');36echo $manager->getHandler();37require_once 'Manager.php';38$manager = new Manager();39$manager->setHandler('10');40echo $manager->getHandler();41require_once 'Manager.php';42$manager = new Manager();43$manager->setHandler('11');44echo $manager->getHandler();
setHandler
Using AI Code Generation
1$manager = new Manager();2$manager->setHandler('handler');3$manager->getHandler();4$manager->setHandler('handler');5$manager->getHandler();6$manager->setHandler('handler');7$manager->getHandler();8$manager->setHandler('handler');9$manager->getHandler();10$manager->setHandler('handler');11$manager->getHandler();12$manager->setHandler('handler');13$manager->getHandler();14$manager->setHandler('handler');15$manager->getHandler();16$manager->setHandler('handler');17$manager->getHandler();18$manager->setHandler('handler');19$manager->getHandler();20$manager->setHandler('handler');21$manager->getHandler();22$manager->setHandler('handler');23$manager->getHandler();24$manager->setHandler('handler');25$manager->getHandler();26$manager->setHandler('handler');27$manager->getHandler();28$manager->setHandler('handler');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with setHandler on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!