mageekguy\atoum\test\engines\concurrent::run PHP Method

run() public method

public run ( test $test )
$test mageekguy\atoum\test
    public function run(atoum\test $test)
    {
        $currentTestMethod = $test->getCurrentMethod();
        if ($currentTestMethod !== null) {
            $this->test = $test;
            $this->method = $currentTestMethod;
            $phpPath = $this->test->getPhpPath();
            $phpCode = '<?php ' . 'ob_start();' . 'require \'' . atoum\directory . '/classes/autoloader.php\';';
            $autoloaderFile = $this->test->getAutoloaderFile();
            if ($autoloaderFile !== null) {
                $phpCode .= '$includer = new mageekguy\\atoum\\includer();' . 'try { $includer->includePath(\'' . $autoloaderFile . '\'); }' . 'catch (mageekguy\\atoum\\includer\\exception $exception)' . '{ die(\'Unable to include autoloader file \\\'' . $autoloaderFile . '\\\'\'); }';
            }
            $bootstrapFile = $this->test->getBootstrapFile();
            if ($bootstrapFile !== null) {
                $phpCode .= '$includer = new mageekguy\\atoum\\includer();' . 'try { $includer->includePath(\'' . $bootstrapFile . '\'); }' . 'catch (mageekguy\\atoum\\includer\\exception $exception)' . '{ die(\'Unable to include bootstrap file \\\'' . $bootstrapFile . '\\\'\'); }';
            }
            $phpCode .= 'require \'' . $this->test->getPath() . '\';' . '$test = new ' . $this->test->getClass() . '();' . '$test->setLocale(new ' . get_class($this->test->getLocale()) . '(' . $this->test->getLocale()->get() . '));' . '$test->setPhpPath(\'' . $phpPath . '\');';
            if ($this->test->debugModeIsEnabled() === true) {
                $phpCode .= '$test->enableDebugMode();';
            }
            if ($this->test->codeCoverageIsEnabled() === false) {
                $phpCode .= '$test->disableCodeCoverage();';
            } else {
                if ($this->test->branchesAndPathsCoverageIsEnabled() === true) {
                    $phpCode .= '$test->enableBranchesAndPathsCoverage();';
                }
                $phpCode .= '$coverage = $test->getCoverage();';
                foreach ($this->test->getCoverage()->getExcludedMethods() as $excludedMethod) {
                    $phpCode .= '$coverage->excludeMethod(\'' . $excludedMethod . '\');';
                }
                foreach ($this->test->getCoverage()->getExcludedClasses() as $excludedClass) {
                    $phpCode .= '$coverage->excludeClass(\'' . $excludedClass . '\');';
                }
                foreach ($this->test->getCoverage()->getExcludedNamespaces() as $excludedNamespace) {
                    $phpCode .= '$coverage->excludeNamespace(\'' . $excludedNamespace . '\');';
                }
                foreach ($this->test->getCoverage()->getExcludedDirectories() as $excludedDirectory) {
                    $phpCode .= '$coverage->excludeDirectory(\'' . $excludedDirectory . '\');';
                }
            }
            if ($this->test->getMockGenerator()->undefinedMethodUsageIsAllowed() === false) {
                $phpCode .= '$test->getMockGenerator()->disallowUndefinedMethodUsage();';
            }
            $extensions = $test->getExtensions();
            foreach ($extensions as $extension) {
                $configuration = $exception = null;
                $extensionClass = get_class($extension);
                try {
                    $configuration = $extensions[$extension];
                } catch (\unexpectedValueException $exception) {
                }
                if ($exception !== null || $configuration === null) {
                    $phpCode .= '$test->addExtension(new ' . $extensionClass . ');';
                } else {
                    $configurationClass = get_class($configuration);
                    $serialized = $configuration->serialize();
                    if (is_array($serialized) === false) {
                        throw new exceptions\logic('Extension (' . $extensionClass . ') configuration (' . $configurationClass . ') should serialize as an array');
                    }
                    $phpCode .= '$test->addExtension(new ' . $extensionClass . ', ' . $configurationClass . '::unserialize(' . var_export($serialized, true) . '));';
                }
            }
            $phpCode .= 'ob_end_clean();' . 'mageekguy\\atoum\\scripts\\runner::disableAutorun();' . 'echo serialize($test->runTestMethod(\'' . $this->method . '\')->getScore());';
            $xdebugConfig = $test->getXdebugConfig();
            if ($xdebugConfig !== null) {
                if (getenv('XDEBUG_CONFIG') !== false || ini_get('xdebug.remote_autostart') != 0) {
                    throw new exceptions\runtime('XDEBUG_CONFIG variable must not be set or value of xdebug.remote_autostart must be 0 to use xdebug with concurrent engine');
                }
                $this->php->XDEBUG_CONFIG = $xdebugConfig;
            }
            $this->php->reset()->setBinaryPath($phpPath)->run($phpCode);
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 public function testGetScore()
 {
     $this->if($engine = new engines\concurrent())->then->variable($engine->getScore())->isNull()->if($engine = new engines\concurrent())->and($engine->setAdapter($adapter = new atoum\test\adapter()))->and($engine->run($test = new \mock\mageekguy\atoum\test()))->then->variable($engine->getScore())->isNull()->if($test->getMockController()->getCurrentMethod = $method = uniqid())->and($test->getMockController()->getPath = $testPath = uniqid())->and($test->getMockController()->getPhpPath = $phpPath = uniqid())->and($test->getMockController()->codeCoverageIsEnabled = false)->and($test->getMockController()->getBootstrapFile = null)->and($adapter->proc_open = function ($command, array $descriptors, array &$pipes) use(&$resource, &$stdIn, &$stdOut, &$stdErr) {
         $pipes = array($stdIn = uniqid(), $stdOut = uniqid(), $stdErr = uniqid());
         return $resource = uniqid();
     })->and($adapter->proc_close = function () {
     })->and($adapter->proc_get_status = array('running' => true))->and($adapter->fwrite = function () {
     })->and($adapter->fclose = function () {
     })->and($adapter->stream_set_blocking = function () {
     })->and($adapter->stream_get_contents = $output = uniqid())->and($engine->run($test))->then->variable($engine->getScore())->isNull()->if($adapter->proc_get_status = array('running' => false, 'exitcode' => $exitCode = rand(1, PHP_INT_MAX)))->then->object($score = $engine->getScore())->isInstanceOf('mageekguy\\atoum\\score')->array($score->getUncompletedMethods())->isEqualTo(array(array('class' => get_class($test), 'method' => $method, 'exitCode' => $exitCode, 'output' => $output . $output)))->if($adapter->stream_get_contents = serialize($score))->and($engine->run($test))->then->object($score = $engine->getScore())->isEqualTo($score);
 }
All Usage Examples Of mageekguy\atoum\test\engines\concurrent::run