Esempio n. 1
0
 public function test__toString()
 {
     $this->if($scoreCoverage = new score\coverage())->and($score = new \mock\mageekguy\atoum\runner\score())->and($score->getMockController()->getCoverage = function () use($scoreCoverage) {
         return $scoreCoverage;
     })->and($runner = new atoum\runner())->and($runner->setScore($score))->and($defaultField = new tests\coverage\cli())->and($customField = new tests\coverage\cli())->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStart, $runner))->and($customField->handleEvent(atoum\runner::runStart, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStop, $runner))->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () {
     })->and($classController->getName = function () use(&$className) {
         return $className;
     })->and($classController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () {
     })->and($methodController->isAbstract = false)->and($methodController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($methodController->getDeclaringClass = $class)->and($methodController->getName = function () use(&$methodName) {
         return $methodName;
     })->and($methodController->getStartLine = 6)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController)))->and($className = uniqid())->and($methodName = uniqid())->and($scoreCoverage->setReflectionClassFactory(function () use($class) {
         return $class;
     }))->and($scoreCoverage->addXdebugDataForTest($this, $xdebugData = array($classFile = uniqid() => array(5 => 1, 6 => 2, 7 => 3, 8 => 2, 9 => 1), uniqid() => array(5 => 2, 6 => 3, 7 => 4, 8 => 3, 9 => 2))))->and($defaultField = new tests\coverage\cli())->and($customField = new tests\coverage\cli())->and($customField->setTitlePrompt($titlePrompt = new prompt(uniqid())))->and($customField->setTitleColorizer($titleColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setClassPrompt($classPrompt = new prompt(uniqid())))->and($customField->setMethodPrompt($methodPrompt = new prompt(uniqid())))->and($customField->setCoverageColorizer($coverageColorizer = new colorizer(uniqid(), uniqid())))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStart, $runner))->and($customField->handleEvent(atoum\runner::runStart, $runner))->then->castToString($defaultField)->isEmpty()->castToString($customField)->isEmpty()->if($defaultField->handleEvent(atoum\runner::runStop, $runner))->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL . $defaultField->getClassPrompt() . sprintf($defaultField->getLocale()->_('Class %s: %3.2f%%'), $className, $scoreCoverage->getValueForClass($className) * 100.0) . PHP_EOL . $defaultField->getMethodPrompt() . sprintf($defaultField->getLocale()->_('%s::%s(): %3.2f%%'), $className, $methodName, $scoreCoverage->getValueForMethod($className, $methodName) * 100.0) . PHP_EOL)->castToString($customField)->isEqualTo($titlePrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize($locale->_('Code coverage value')), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValue() * 100.0))) . PHP_EOL . $classPrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize(sprintf($locale->_('Class %s'), $className)), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className) * 100.0))) . PHP_EOL . $methodPrompt . sprintf($locale->_('%s: %s'), $titleColorizer->colorize(sprintf($locale->_('%s::%s()'), $className, $methodName)), $coverageColorizer->colorize(sprintf('%3.2f%%', $scoreCoverage->getValueForClass($className, $methodName) * 100.0))) . PHP_EOL)->if($defaultField->hideMethodsCoverageDetails())->and($defaultField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL . $defaultField->getClassPrompt() . sprintf($defaultField->getLocale()->_('Class %s: %3.2f%%'), $className, $scoreCoverage->getValueForClass($className) * 100.0) . PHP_EOL)->if($defaultField->hideClassesCoverageDetails())->and($defaultField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($defaultField)->isEqualTo($defaultField->getTitlePrompt() . sprintf($defaultField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL)->if($customField->hideClassesCoverageDetails())->and($customField->handleEvent(atoum\runner::runStop, $runner))->then->castToString($customField)->isEqualTo($customField->getTitlePrompt() . sprintf($customField->getLocale()->_('Code coverage value: %3.2f%%'), $scoreCoverage->getValue() * 100) . PHP_EOL);
 }
Esempio n. 2
0
 public function testSetPathAndVersionInScore()
 {
     $this->if($score = new \mock\mageekguy\atoum\runner\score())->and($scoreController = $score->getMockController())->and($adapter = new atoum\test\adapter())->and($adapter->defined = false)->and($adapter->proc_open = false)->and($adapter->defined = function ($constant) {
         return $constant == 'PHP_BINARY';
     })->and($adapter->constant = function ($constant) use(&$phpPath) {
         return $constant != 'PHP_BINARY' ? null : ($phpPath = uniqid());
     })->and($adapter->realpath = function ($path) {
         return $path;
     })->and($runner = new atoum\runner())->and($runner->setScore($score))->and($runner->setAdapter($adapter))->then->exception(function () use($runner) {
         $runner->setPathAndVersionInScore();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to open \'' . $phpPath . '\'')->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->mock($score)->call('setAtoumVersion')->withArguments(null)->once()->call('setAtoumPath')->withArguments(null)->once()->call('setPhpPath')->never()->call('setPhpVersion')->never()->if($adapter->realpath = false)->and($adapter->resetCalls())->and($score->reset())->and($scoreController->resetCalls())->then->exception(function () use($runner) {
         $runner->setPathAndVersionInScore();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to find \'' . $phpPath . '\'')->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->mock($score)->call('setAtoumVersion')->withArguments(null)->once()->call('setAtoumPath')->withArguments(null)->once()->call('setPhpPath')->never()->call('setPhpVersion')->never()->if($adapter->resetCalls())->and($adapter->realpath = function ($path) {
         return $path;
     })->and($adapter->proc_open = function ($cmd, $descriptors, &$pipes) use(&$php, &$stdOut, &$stdErr) {
         $pipes = array(1 => $stdOut = uniqid(), 2 => $stErr = uniqid());
         return $php = uniqid();
     })->and($adapter->stream_get_contents = $phpVersion = uniqid())->and($adapter->fclose = function () {
     })->and($adapter->proc_close = function () {
     })->and($adapter->proc_terminate = function () {
     })->and($adapter->proc_get_status = array('running' => false, 'exitcode' => 126))->and($score->reset())->and($scoreController->resetCalls())->then->exception(function () use($runner) {
         $runner->setPathAndVersionInScore();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to get PHP version from \'' . $phpPath . '\'')->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->call('proc_close')->withArguments($php)->once()->mock($score)->call('setAtoumVersion')->withArguments(null)->once()->call('setAtoumPath')->withArguments(null)->once()->call('setPhpPath')->never()->call('setPhpVersion')->never()->if($adapter->resetCalls())->and($adapter->proc_get_status = array('running' => false, 'exitcode' => 127))->and($score->reset())->and($scoreController->reset())->then->exception(function () use($runner) {
         $runner->setPathAndVersionInScore();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to get PHP version from \'' . $phpPath . '\'')->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->call('proc_close')->withArguments($php)->once()->mock($score)->call('setAtoumVersion')->withArguments(null)->once()->call('setAtoumPath')->withArguments(null)->once()->call('setPhpPath')->never()->call('setPhpVersion')->never()->if($adapter->resetCalls())->and($adapter->proc_get_status = array('exitcode' => 0, 'running' => false))->and($score->reset())->and($scoreController->resetCalls())->then->object($runner->setPathAndVersionInScore())->isIdenticalTo($runner)->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->call('stream_get_contents')->withArguments($stdOut)->once()->call('fclose')->withArguments($stdOut)->once()->call('proc_close')->withArguments($php)->once()->mock($score)->call('setAtoumVersion')->withArguments(null)->once()->call('setAtoumPath')->withArguments(null)->once()->call('setPhpPath')->withArguments($phpPath)->once()->call('setPhpVersion')->withArguments($phpVersion)->once()->if($adapter->defined = true)->and($adapter->constant = function ($constantName) use(&$atoumVersion, &$atoumDirectory) {
         switch ($constantName) {
             case atoum\runner::atoumVersionConstant:
                 return $atoumVersion = uniqid();
             case atoum\runner::atoumDirectoryConstant:
                 return $atoumDirectory = uniqid();
         }
     })->and($adapter->resetCalls())->and($score->reset())->and($scoreController->resetCalls())->then->object($runner->setPathAndVersionInScore())->isIdenticalTo($runner)->adapter($adapter)->call('realpath')->withArguments($phpPath)->once()->call('defined')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('constant')->withArguments(atoum\runner::atoumVersionConstant)->once()->call('defined')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->call('constant')->withArguments(atoum\runner::atoumDirectoryConstant)->once()->call('stream_get_contents')->withArguments($stdOut)->once()->call('fclose')->withArguments($stdOut)->once()->call('proc_close')->withArguments($php)->once()->mock($score)->call('setAtoumVersion')->withArguments($atoumVersion)->once()->call('setAtoumPath')->withArguments($atoumDirectory)->once()->call('setPhpPath')->withArguments($phpPath)->once()->call('setPhpVersion')->withArguments($phpVersion)->once();
 }