Inheritance: extends mageekguy\atoum\asserter
Esempio n. 1
0
 protected function callIsSet()
 {
     try {
         return parent::callIsSet();
     } catch (call\exceptions\logic $exception) {
         throw new exceptions\logic('Call is undefined');
     }
 }
Esempio n. 2
0
 public function runTestMethod($testMethod, array $tags = array())
 {
     if ($this->methodIsIgnored($testMethod, $tags) === false) {
         $mockGenerator = $this->getMockGenerator();
         $mockNamespacePattern = '/^' . preg_quote($mockGenerator->getDefaultNamespace()) . '\\\\/i';
         $mockAutoloader = function ($class) use($mockGenerator, $mockNamespacePattern) {
             $mockedClass = preg_replace($mockNamespacePattern, '', $class);
             if ($mockedClass !== $class) {
                 $mockGenerator->generate($mockedClass);
             }
         };
         if (spl_autoload_register($mockAutoloader, true, true) === false) {
             throw new \runtimeException('Unable to register mock autoloader');
         }
         set_error_handler(array($this, 'errorHandler'));
         ini_set('display_errors', 'stderr');
         ini_set('log_errors', 'Off');
         ini_set('log_errors_max_len', '0');
         $this->currentMethod = $testMethod;
         $this->executeOnFailure = array();
         $this->phpMocker->setDefaultNamespace($this->getTestedClassNamespace());
         try {
             foreach ($this->getMethodPhpVersions($testMethod) as $phpVersion => $operator) {
                 if (version_compare(phpversion(), $phpVersion, $operator) === false) {
                     throw new test\exceptions\skip('PHP version ' . PHP_VERSION . ' is not ' . $operator . ' to ' . $phpVersion);
                 }
             }
             foreach ($this->getMandatoryMethodExtensions($testMethod) as $mandatoryExtension) {
                 $this->extension($mandatoryExtension)->isLoaded();
             }
             try {
                 ob_start();
                 if ($this->adapter->class_exists($testedClassName = $this->getTestedClassName()) === false) {
                     throw new exceptions\runtime('Tested class \'' . $testedClassName . '\' does not exist for test class \'' . $this->getClass() . '\'');
                 }
                 test\adapter::setStorage($this->testAdapterStorage);
                 mock\controller::setLinker($this->mockControllerLinker);
                 $this->testAdapterStorage->add(php\mocker::getAdapter());
                 $this->beforeTestMethod($this->currentMethod);
                 if ($this->codeCoverageIsEnabled() === true) {
                     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
                 }
                 $assertionNumber = $this->score->getAssertionNumber();
                 $time = microtime(true);
                 $memory = memory_get_usage(true);
                 if (isset($this->dataProviders[$testMethod]) === false) {
                     $this->{$testMethod}();
                     asserters\adapter\call::areEvaluated();
                 } else {
                     $data = $this->{$this->dataProviders[$testMethod]}();
                     if (is_array($data) === false && $data instanceof \traversable === false) {
                         throw new test\exceptions\runtime('Data provider ' . $this->getClass() . '::' . $this->dataProviders[$testMethod] . '() must return an array or an iterator');
                     }
                     $reflectedTestMethod = call_user_func($this->reflectionMethodFactory, $this, $testMethod);
                     $numberOfArguments = $reflectedTestMethod->getNumberOfRequiredParameters();
                     foreach ($data as $key => $arguments) {
                         if (is_array($arguments) === false) {
                             $arguments = array($arguments);
                         }
                         if (sizeof($arguments) != $numberOfArguments) {
                             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 . '()');
                         }
                         $this->score->setDataSet($key, $this->dataProviders[$testMethod]);
                         $reflectedTestMethod->invokeArgs($this, $arguments);
                         asserters\adapter\call::areEvaluated();
                         $this->score->unsetDataSet();
                     }
                 }
                 $this->mockControllerLinker->reset();
                 $this->testAdapterStorage->reset();
                 $memoryUsage = memory_get_usage(true) - $memory;
                 $duration = microtime(true) - $time;
                 $this->score->addMemoryUsage($this->path, $this->class, $this->currentMethod, $memoryUsage)->addDuration($this->path, $this->class, $this->currentMethod, $duration)->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean());
                 if ($this->codeCoverageIsEnabled() === true) {
                     $this->score->getCoverage()->addXdebugDataForTest($this, xdebug_get_code_coverage());
                     xdebug_stop_code_coverage();
                 }
                 if ($assertionNumber == $this->score->getAssertionNumber() && $this->methodIsNotVoid($this->currentMethod) === false) {
                     $this->score->addVoidMethod($this->path, $this->class, $this->currentMethod);
                 }
             } catch (\exception $exception) {
                 $this->score->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean());
                 throw $exception;
             }
         } catch (asserter\exception $exception) {
             foreach ($this->executeOnFailure as $closure) {
                 ob_start();
                 $closure();
                 $this->score->addOutput($this->path, $this->class, $this->currentMethod, ob_get_clean());
             }
             if ($this->score->failExists($exception) === false) {
                 $this->addExceptionToScore($exception);
             }
         } catch (test\exceptions\runtime $exception) {
             $this->score->addRuntimeException($this->path, $this->class, $this->currentMethod, $exception);
         } catch (test\exceptions\skip $exception) {
             list($file, $line) = $this->getBacktrace($exception->getTrace());
             $this->score->addSkippedMethod($file, $this->class, $this->currentMethod, $line, $exception->getMessage());
         } catch (test\exceptions\stop $exception) {
         } catch (exception $exception) {
             list($file, $line) = $this->getBacktrace($exception->getTrace());
             $this->errorHandler(E_USER_ERROR, $exception->getMessage(), $file, $line);
         } catch (\exception $exception) {
             $this->addExceptionToScore($exception);
         }
         $this->afterTestMethod($this->currentMethod);
         $this->currentMethod = null;
         restore_error_handler();
         ini_restore('display_errors');
         ini_restore('log_errors');
         ini_restore('log_errors_max_len');
         if (spl_autoload_unregister($mockAutoloader) === false) {
             throw new \runtimeException('Unable to unregister mock autoloader');
         }
     }
     return $this;
 }
Esempio n. 3
0
 private function addAfterCall(call $call)
 {
     $this->afterCalls[] = $call->disableEvaluationChecking();
     return $this;
 }
Esempio n. 4
0
 public function after(call $call)
 {
     $this->setLastAssertion(__METHOD__)->afterCalls[] = $call->disableEvaluationChecking();
     return $this;
 }