public function testHandleEvent() { $this->if($adapter = new atoum\test\adapter())->and($adapter->extension_loaded = true)->and($adapter->exec = function ($command) { switch ($command) { case 'git log -1 --pretty=format:\'{"id":"%H","author_name":"%aN","author_email":"%ae","committer_name":"%cN","committer_email":"%ce","message":"%s"}\'': return '{"id":"7282ea7620b45fcba0f9d3bfd484ab146aba2bd0","author_name":"mageekguy","author_email":"*****@*****.**","comitter_name":"mageekguy","comitter_email":"*****@*****.**"}'; case 'git rev-parse --abbrev-ref HEAD': return 'master'; default: return null; } })->and($report = new testedClass($sourceDir = uniqid(), $token = '51bb597d202b4', $adapter))->and($score = new \mock\mageekguy\atoum\score())->and($coverage = new \mock\mageekguy\atoum\score\coverage())->and($writer = new \mock\mageekguy\atoum\writers\http())->and($writer->getMockController()->writeAsynchronousReport = function () use($writer) { return $writer; })->then->when(function () use($report, $writer) { $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner()); })->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->if($adapter->date = '2013-05-13 10:00:00 +0000')->and($adapter->file_get_contents = '<?php')->and($observable = new \mock\mageekguy\atoum\runner())->and($observable->getMockController()->getScore = $score)->and($score->getMockController()->getCoverage = $coverage)->and($coverage->getMockController()->getClasses = array())->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '1.json')))->and($report = new testedClass($sourceDir, $token, $adapter))->and($report->addWriter($writer))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->if($coverage->getMockController()->getClasses = array())->and($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = $className = 'bar')->and($classController->getFileName = $classFile = 'foo/bar.php')->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->getName = $methodName = 'baz')->and($methodController->isAbstract = false)->and($methodController->getFileName = $classFile)->and($methodController->getDeclaringClass = $class)->and($methodController->getStartLine = 4)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod($className, $methodName, $methodController)))->and($coverage->getMockController()->getClasses = array($className => $classFile, 'foo' => 'bar/foo.php'))->and($xdebugData = array($classFile => array(3 => 1, 4 => 1, 5 => -2, 6 => 0, 7 => -1, 8 => 1, 9 => 1)))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '2' . (defined('PHP_WINDOWS_VERSION_MAJOR') === true ? '-windows' : '') . '.json')))->and($coverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($coverage->addXdebugDataForTest($this, $xdebugData))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->twice()->if($finder = function () use(&$branch) { return 'feature'; })->and($report->setBranchFinder($finder))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'coveralls', 'resources', '3' . (defined('PHP_WINDOWS_VERSION_MAJOR') === true ? '-windows' : '') . '.json')))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->thrice()->if($report->setBranchFinder(function () use(&$branch) { return $branch = uniqid(); }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->contains('"branch":"' . $branch . '"')->if($report->setBranchFinder(function () { }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->notContains('"branch":')->if($report->setBranchFinder(function () { return ''; }))->and($report->handleEvent(atoum\runner::runStop, $observable))->then->castToString($report)->notContains('"branch":'); }
public function test__toString() { $this->if($field = new testedClass(uniqid(), uniqid()))->then->castToString($field)->isEqualTo('Code coverage: unknown.' . PHP_EOL)->if($coverage = new \mock\mageekguy\atoum\score\coverage())->and($coverageController = $coverage->getMockController())->and($coverageController->count = rand(1, PHP_INT_MAX))->and($coverageController->getClasses = array($className = uniqid() => $classFile = uniqid()))->and($coverageController->getMethods = array($className => array($method1Name = uniqid() => array(5 => 1, 6 => 1, 7 => -1, 8 => 1, 9 => -2), $method3Name = uniqid() => array(10 => -2), $method4Name = uniqid() => array(11 => 1, 12 => -2))))->and($coverageController->getValue = $coverageValue = rand(1, 10) / 10)->and($coverageController->getValueForClass = $classCoverageValue = rand(1, 10) / 10)->and($coverageController->getValueForMethod = $methodCoverageValue = rand(1, 10) / 10)->and($score = new \mock\mageekguy\atoum\score())->and($score->getMockController()->getCoverage = $coverage)->if($classCoverageTemplate = new \mock\mageekguy\atoum\template\tag('classCoverage'))->and($classCoverageTemplate->addChild($classCoverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('classCoverageAvailable')))->and($indexTemplate = new \mock\mageekguy\atoum\template())->and($indexTemplate->addChild($coverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('coverageAvailable'))->addChild($classCoverageTemplate))->and($indexTemplateController = $indexTemplate->getMockController())->and($indexTemplateController->__set = function () { })->and($indexTemplateController->build = $buildOfIndexTemplate = uniqid())->and($methodTemplate = new \mock\mageekguy\atoum\template())->and($methodTemplateController = $methodTemplate->getMockController())->and($methodTemplateController->__set = function () { })->and($lineTemplate = new \mock\mageekguy\atoum\template\tag('line'))->and($lineTemplateController = $lineTemplate->getMockController())->and($lineTemplateController->__set = function () { })->and($coveredLineTemplate = new \mock\mageekguy\atoum\template\tag('coveredLine'))->and($coveredLineTemplateController = $coveredLineTemplate->getMockController())->and($coveredLineTemplateController->__set = function () { })->and($notCoveredLineTemplate = new \mock\mageekguy\atoum\template\tag('notCoveredLine'))->and($notCoveredLineTemplateController = $notCoveredLineTemplate->getMockController())->and($notCoveredLineTemplateController->__set = function () { })->and($sourceFileTemplate = new \mock\mageekguy\atoum\template\tag('sourceFile'))->and($sourceFileTemplateController = $sourceFileTemplate->getMockController())->and($sourceFileTemplateController->__set = function () { })->and($sourceFileTemplate->addChild($lineTemplate)->addChild($coveredLineTemplate)->addChild($notCoveredLineTemplate))->and($methodCoverageAvailableTemplate = new \mock\mageekguy\atoum\template\tag('methodCoverageAvailable'))->and($methodTemplate = new \mock\mageekguy\atoum\template\tag('method'))->and($methodTemplate->addChild($methodCoverageAvailableTemplate))->and($methodsTemplate = new \mock\mageekguy\atoum\template\tag('methods'))->and($methodsTemplate->addChild($methodTemplate))->and($classTemplate = new \mock\mageekguy\atoum\template())->and($classTemplateController = $classTemplate->getMockController())->and($classTemplateController->__set = function () { })->and($classTemplate->addChild($methodsTemplate)->addChild($sourceFileTemplate))->and($reflectedClassController = new mock\controller())->and($reflectedClassController->__construct = function () { })->and($reflectedClassController->getName = $className)->and($reflectedClass = new \mock\reflectionClass(uniqid(), $reflectedClassController))->and($otherReflectedClassController = new mock\controller())->and($otherReflectedClassController->__construct = function () { })->and($otherReflectedClassController->getName = uniqid())->and($otherReflectedClass = new \mock\reflectionClass(uniqid(), $otherReflectedClassController))->and($reflectedMethod1Controller = new mock\controller())->and($reflectedMethod1Controller->__construct = function () { })->and($reflectedMethod1Controller->getName = $method1Name)->and($reflectedMethod1Controller->isAbstract = false)->and($reflectedMethod1Controller->getDeclaringClass = $reflectedClass)->and($reflectedMethod1Controller->getStartLine = 5)->and($reflectedMethod1 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod1Controller))->and($reflectedMethod2Controller = new mock\controller())->and($reflectedMethod2Controller->__construct = function () { })->and($reflectedMethod2Controller->getName = $method2Name = uniqid())->and($reflectedMethod2Controller->isAbstract = false)->and($reflectedMethod2Controller->getDeclaringClass = $otherReflectedClass)->and($reflectedMethod2Controller->getStartLine = 5)->and($reflectedMethod2 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod2Controller))->and($reflectedMethod3Controller = new mock\controller())->and($reflectedMethod3Controller->__construct = function () { })->and($reflectedMethod3Controller->getName = $method3Name)->and($reflectedMethod3Controller->isAbstract = true)->and($reflectedMethod3Controller->getDeclaringClass = $reflectedClass)->and($reflectedMethod3Controller->getStartLine = 10)->and($reflectedMethod3 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod3Controller))->and($reflectedMethod4Controller = new mock\controller())->and($reflectedMethod4Controller->__construct = function () { })->and($reflectedMethod4Controller->getName = $method4Name)->and($reflectedMethod4Controller->isAbstract = false)->and($reflectedMethod4Controller->getDeclaringClass = $reflectedClass)->and($reflectedMethod4Controller->getStartLine = 11)->and($reflectedMethod4 = new \mock\reflectionMethod(uniqid(), uniqid(), $reflectedMethod4Controller))->and($reflectedClassController->getMethods = array($reflectedMethod1, $reflectedMethod2, $reflectedMethod3, $reflectedMethod4))->and($templateParser = new \mock\mageekguy\atoum\template\parser())->and($field = new \mock\mageekguy\atoum\report\fields\runner\coverage\html($projectName = uniqid(), $destinationDirectory = uniqid()))->and($field->setTemplateParser($templateParser)->setTemplatesDirectory($templatesDirectory = uniqid())->setAdapter($adapter = new test\adapter()))->and($fieldController = $field->getMockController())->and($fieldController->cleanDestinationDirectory = function () { })->and($fieldController->getReflectionClass = $reflectedClass)->and($runner = new \mock\mageekguy\atoum\runner())->and($runner->getMockController()->getScore = $score)->and($field->setRootUrl($rootUrl = uniqid()))->and($templateParserController = $templateParser->getMockController())->and($templateParserController->parseFile = function ($path) use($templatesDirectory, $indexTemplate, $classTemplate) { switch ($path) { case $templatesDirectory . DIRECTORY_SEPARATOR . 'index.tpl': return $indexTemplate; case $templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl': return $classTemplate; } })->and($adapter->mkdir = function () { })->and($adapter->file_put_contents = function () { })->and($adapter->filemtime = $filemtime = time())->and($adapter->fopen = $classResource = uniqid())->and($adapter->fgets = false)->and($adapter->fgets[1] = $line1 = uniqid())->and($adapter->fgets[2] = $line2 = uniqid())->and($adapter->fgets[3] = $line3 = uniqid())->and($adapter->fgets[4] = $line4 = uniqid())->and($adapter->fgets[5] = $line5 = uniqid())->and($adapter->fgets[6] = $line6 = uniqid())->and($adapter->fgets[7] = $line7 = uniqid())->and($adapter->fgets[8] = $line8 = uniqid())->and($adapter->fgets[9] = $line9 = uniqid())->and($adapter->fgets[10] = $line10 = uniqid())->and($adapter->fgets[11] = $line11 = uniqid())->and($adapter->fgets[12] = $line12 = uniqid())->and($adapter->fgets[13] = $line13 = uniqid())->and($adapter->fgets[14] = $line14 = uniqid())->and($adapter->fgets[15] = $line15 = uniqid())->and($adapter->fclose = function () { })->and($adapter->copy = function () { })->and($field->handleEvent(atoum\runner::runStop, $runner))->then->object($field->getCoverage())->isIdenticalTo($coverage)->castToString($field)->isIdenticalTo(sprintf($field->getLocale()->_('Code coverage: %3.2f%%.'), round($coverageValue * 100, 2)) . PHP_EOL . 'Details of code coverage are available at ' . $rootUrl . '.' . PHP_EOL)->mock($coverage)->call('count')->once()->mock($field)->call('cleanDestinationDirectory')->once()->mock($coverage)->call('count')->once()->call('getClasses')->once()->call('getMethods')->once()->call('getValueForClass')->withArguments($className)->atLeastOnce()->call('getValueForMethod')->withArguments($className, $method1Name)->once()->call('getValueForMethod')->withArguments($className, $method2Name)->never()->call('getValueForMethod')->withArguments($className, $method3Name)->never()->call('getValueForMethod')->withArguments($className, $method4Name)->once()->mock($templateParser)->call('parseFile')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'index.tpl', null)->once()->call('parseFile')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl', null)->once()->mock($indexTemplate)->call('__set')->withArguments('projectName', $projectName)->once()->call('__set')->withArguments('rootUrl', $rootUrl)->once()->call('__get')->withArguments('coverageAvailable')->once()->call('__get')->withArguments('classCoverage')->once()->mock($coverageAvailableTemplate)->call('build')->withArguments(array('coverageValue' => round($coverageValue * 100, 2)))->once()->mock($classTemplate)->call('__set')->withArguments('rootUrl', $rootUrl)->once()->call('__set')->withArguments('projectName', $projectName)->once()->call('__set')->withArguments('className', $className)->once()->call('__get')->withArguments('methods')->once()->call('__get')->withArguments('sourceFile')->once()->call('build')->once()->mock($classCoverageTemplate)->call('__set')->withArguments('className', $className)->once()->call('__set')->withArguments('classUrl', str_replace('\\', '/', $className) . testedClass::htmlExtensionFile)->once()->call('build')->once()->mock($classCoverageAvailableTemplate)->call('build')->withArguments(array('classCoverageValue' => round($classCoverageValue * 100, 2)))->once()->call('resetData')->atLeastOnce()->mock($methodsTemplate)->call('build')->once()->call('resetData')->atLeastOnce()->mock($methodTemplate)->call('build')->atLeastOnce()->call('resetData')->atLeastOnce()->mock($methodCoverageAvailableTemplate)->call('__set')->withArguments('methodName', $method1Name)->once()->call('__set')->withArguments('methodName', $method2Name)->never()->call('__set')->withArguments('methodName', $method3Name)->never()->call('__set')->withArguments('methodName', $method4Name)->once()->call('__set')->withArguments('methodCoverageValue', round($methodCoverageValue * 100, 2))->atLeastOnce()->call('build')->atLeastOnce()->call('resetData')->atLeastOnce()->mock($lineTemplate)->call('__set')->withArguments('code', $line1)->once()->call('__set')->withArguments('code', $line2)->once()->call('__set')->withArguments('code', $line3)->once()->call('__set')->withArguments('code', $line4)->once()->call('__set')->withArguments('code', $line9)->once()->call('__set')->withArguments('code', $line12)->once()->mock($coveredLineTemplate)->call('__set')->withArguments('code', $line5)->once()->call('__set')->withArguments('code', $line6)->once()->call('__set')->withArguments('code', $line8)->once()->call('__set')->withArguments('code', $line11)->once()->mock($notCoveredLineTemplate)->call('__set')->withArguments('code', $line7)->once()->adapter($adapter)->call('file_put_contents')->withArguments($destinationDirectory . DIRECTORY_SEPARATOR . 'index.html', $buildOfIndexTemplate)->once()->call('copy')->withArguments($templatesDirectory . DIRECTORY_SEPARATOR . 'screen.css', $destinationDirectory . DIRECTORY_SEPARATOR . 'screen.css')->once()->call('fopen')->withArguments($classFile, 'r')->once()->call('fgets')->withArguments($classResource)->atLeastOnce()->call('fclose')->withArguments($classResource)->once()->if($indexTemplateController->build->throw = new \exception($errorMessage = uniqid()))->then->castToString($field)->isIdenticalTo(sprintf($field->getLocale()->_('Code coverage: %3.2f%%.'), round($coverageValue * 100, 2)) . PHP_EOL . 'Unable to generate code coverage at ' . $rootUrl . ': ' . $errorMessage . '.' . PHP_EOL); }
public function testHandleEvent() { $this->if($adapter = new atoum\test\adapter())->if($adapter->extension_loaded = true)->and($report = new testedClass($adapter))->and($score = new \mock\mageekguy\atoum\score())->and($coverage = new \mock\mageekguy\atoum\score\coverage())->and($writer = new \mock\mageekguy\atoum\writers\file())->and($writer->getMockController()->write = $writer)->then->when(function () use($report, $writer) { $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner()); })->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()->and($adapter->time = 762476400)->and($adapter->uniqid = 'foo')->and($observable = new \mock\mageekguy\atoum\runner())->and($observable->getMockController()->getScore = $score)->and($score->getMockController()->getCoverage = $coverage)->and($coverage->getMockController()->getClasses = array())->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'clover', 'resources', '1.xml')))->and($report = new testedClass($adapter))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath)->if($coverage->getMockController()->getClasses = array())->and($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () { })->and($classController->getName = $className = 'bar')->and($classController->getFileName = $classFile = 'foo/bar.php')->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->getName = $methodName = 'baz')->and($methodController->isAbstract = false)->and($methodController->getFileName = $classFile)->and($methodController->getDeclaringClass = $class)->and($methodController->getStartLine = 4)->and($methodController->getEndLine = 8)->and($classController->getMethods = array(new \mock\reflectionMethod($className, $methodName, $methodController)))->and($coverage->getMockController()->getClasses = array($className => $classFile, 'foo' => 'bar/foo.php'))->and($xdebugData = array($classFile => array(3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 1, 8 => 1, 9 => 1)))->and($filepath = join(DIRECTORY_SEPARATOR, array(__DIR__, 'clover', 'resources', '2.xml')))->and($coverage->setReflectionClassFactory(function () use($class) { return $class; }))->and($coverage->addXdebugDataForTest($this, $xdebugData))->then->object($report->handleEvent(atoum\runner::runStop, $observable))->isIdenticalTo($report)->castToString($report)->isEqualToContentsOfFile($filepath); }
public function testCheckUnitTests() { $builder = new \mock\mageekguy\atoum\scripts\builder(uniqid(), $adapter = new atoum\test\adapter()); $builder->disableUnitTestChecking(); $this->assert->boolean($builder->unitTestCheckingIsEnabled())->isFalse()->boolean($builder->checkUnitTests())->isTrue(); $builder->enableUnitTestChecking(); $this->assert->exception(function () use($builder) { $builder->checkUnitTests(); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Unable to check unit tests, working directory is undefined'); $builder->setWorkingDirectory($workingDirectory = uniqid()); $vcsController = new mock\controller(); $vcsController->__construct = function () { }; $vcsController->exportRepository = function () { }; $builder->setVcs($vcs = new \mock\mageekguy\atoum\scripts\builder\vcs(null, $vcsController)); $builder->setUnitTestRunnerScript($unitTestRunnerScript = uniqid())->setPhpPath($php = uniqid())->setReportTitle($reportTitle = uniqid())->addRunnerConfigurationFile($runnerConfigurationFile = uniqid()); $score = new \mock\mageekguy\atoum\score(); $scoreController = $score->getMockController(); $scoreController->getFailNumber = 0; $scoreController->getExceptionNumber = 0; $scoreController->getErrorNumber = 0; $adapter->sys_get_temp_dir = $tempDirectory = uniqid(); $adapter->tempnam = $scoreFile = uniqid(); $adapter->proc_open = function ($bin, $descriptors, &$stream) use(&$stdOut, &$stdErr, &$pipes, &$resource) { $pipes = array(1 => $stdOut = uniqid(), 2 => $stdErr = uniqid()); $stream = $pipes; return $resource = uniqid(); }; $adapter->proc_get_status = array('exit_code' => 0, 'running' => true); $adapter->stream_get_contents = function () { return ''; }; $adapter->fclose = function () { }; $adapter->proc_close = function () { }; $adapter->file_get_contents = $scoreFileContents = uniqid(); $adapter->unserialize = $score; $adapter->unlink = true; $command = escapeshellarg($php) . ' ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . $unitTestRunnerScript) . ' -drt ' . escapeshellarg($reportTitle) . ' -ncc -sf ' . escapeshellarg($scoreFile) . ' -d ' . escapeshellarg($workingDirectory . \DIRECTORY_SEPARATOR . 'tests' . \DIRECTORY_SEPARATOR . 'units' . \DIRECTORY_SEPARATOR . 'classes') . ' -p ' . escapeshellarg($php) . ' -c ' . escapeshellarg($runnerConfigurationFile); $builderController = $builder->getMockController(); $builderController->writeErrorInErrorsDirectory = function () { }; $this->assert->boolean($builder->checkUnitTests())->isTrue()->mock($vcs)->call('setWorkingDirectory')->withArguments($workingDirectory)->once()->mock($vcs)->call('exportRepository')->once()->adapter($adapter)->call('sys_get_temp_dir')->once()->call('tempnam')->withArguments($tempDirectory, '')->once()->call('proc_open')->withArguments($command, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes)->once()->call('proc_get_status')->withArguments($resource)->once()->call('stream_get_contents')->withArguments($stdOut)->once()->call('fclose')->withArguments($stdOut)->once()->call('stream_get_contents')->withArguments($stdErr)->once()->call('fclose')->withArguments($stdErr)->once()->call('proc_close')->withArguments($resource)->once()->call('file_get_contents')->withArguments($scoreFile)->once()->call('unserialize')->withArguments($scoreFileContents)->once()->call('unlink')->withArguments($scoreFile)->once()->mock($score)->call('getFailNumber')->once()->call('getExceptionNumber')->once()->call('getErrorNumber')->once(); $adapter->proc_open = false; $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to execute \'' . $command . '\'')->once(); $adapter->proc_open = function ($bin, $descriptors, &$stream) use(&$stdOut, &$stdErr, &$pipes, &$resource) { $pipes = array(1 => $stdOut = uniqid(), 2 => $stdErr = uniqid()); $stream = $pipes; return $resource = uniqid(); }; $adapter->proc_get_status = array('exitcode' => 126, 'running' => false); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to find \'' . $php . '\' or it is not executable')->once(); $adapter->proc_get_status = array('exitcode' => 127, 'running' => false); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to find \'' . $php . '\' or it is not executable')->once(); $adapter->proc_get_status = array('exitcode' => $exitCode = rand(1, 125), 'running' => false); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Command \'' . $command . '\' failed with exit code \'' . $exitCode . '\'')->once(); $adapter->proc_get_status = array('exitcode' => $exitCode = rand(128, PHP_INT_MAX), 'running' => false); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Command \'' . $command . '\' failed with exit code \'' . $exitCode . '\'')->once(); $adapter->proc_get_status = array('exit_code' => 0, 'running' => true); $adapter->stream_get_contents = function ($stream) use(&$stdOut, &$stdOutContents) { return $stream != $stdOut ? '' : ($stdOutContents = uniqid()); }; $this->assert->boolean($builder->checkUnitTests())->isTrue()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($stdOutContents)->never(); $adapter->stream_get_contents = function ($stream) use(&$stdErr, &$stdErrContents) { return $stream != $stdErr ? '' : ($stdErrContents = uniqid()); }; $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments($stdErrContents)->once(); $adapter->stream_get_contents = ''; $adapter->file_get_contents = false; $builder->getMockController()->resetCalls(); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to read score from file \'' . $scoreFile . '\'')->once(); $adapter->file_get_contents = $scoreFileContents; $adapter->unserialize = false; $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Unable to unserialize score from file \'' . $scoreFile . '\'')->once(); $adapter->unserialize = uniqid(); $this->assert->boolean($builder->checkUnitTests())->isFalse()->mock($builder)->call('writeErrorInErrorsDirectory')->withArguments('Contents of file \'' . $scoreFile . '\' is not a score')->once(); $adapter->unserialize = $score; $adapter->unlink = false; $this->assert->exception(function () use($builder) { $builder->checkUnitTests(); })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Unable to delete score file \'' . $scoreFile . '\''); $adapter->unlink = true; $scoreController->getFailNumber = rand(1, PHP_INT_MAX); $this->assert->boolean($builder->checkUnitTests())->isFalse(); $scoreController->getFailNumber = 0; $scoreController->getExceptionNumber = rand(1, PHP_INT_MAX); $this->assert->boolean($builder->checkUnitTests())->isFalse(); $scoreController->getExceptionNumber = 0; $scoreController->getErrorNumber = rand(1, PHP_INT_MAX); $this->assert->boolean($builder->checkUnitTests())->isFalse(); }
public function test__toString() { $this->if($adapter = new adapter())->and($adapter->class_exists = true)->and($score = new \mock\mageekguy\atoum\score())->and($score->getMockController()->getTotalDuration = $runningDuration = rand(1, 1000) / 1000)->and($testController = new mock\controller())->and($testController->getTestedClassName = uniqid())->and($testController->getScore = $score)->and($test = new \mock\mageekguy\atoum\test($adapter))->and($defaultField = new test\duration\phing())->and($customField = new test\duration\phing())->and($customField->setPrompt($prompt = new prompt()))->and($customField->setTitleColorizer($titleColorizer = new colorizer()))->and($customField->setDurationColorizer($durationColorizer = new colorizer()))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEqualTo('unknown')->castToString($customField)->isEqualTo($prompt . sprintf('%s', $locale->_('unknown')))->if($defaultField->handleEvent(atoum\runner::runStop, $test))->then->castToString($defaultField)->isEqualTo('unknown')->if($customField->handleEvent(atoum\runner::runStop, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf('%s', $locale->_('unknown')))->if($defaultField->handleEvent(atoum\test::runStop, $test))->then->castToString($defaultField)->isEqualTo(sprintf('%4.2f s', $runningDuration))->if($customField->handleEvent(atoum\test::runStop, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf('%s', $durationColorizer->colorize(sprintf($locale->__('%4.2f s', '%4.2f s', $runningDuration), $runningDuration))))->if($score->getMockController()->getTotalDuration = $runningDuration = rand(2, PHP_INT_MAX))->and($defaultField = new test\duration\phing())->and($customField = new test\duration\phing())->and($customField->setPrompt($prompt = new prompt()))->and($customField->setTitleColorizer($titleColorizer = new colorizer()))->and($customField->setDurationColorizer($durationColorizer = new colorizer()))->and($customField->setLocale($locale = new locale()))->then->castToString($defaultField)->isEqualTo('unknown')->castToString($customField)->isEqualTo($prompt . sprintf('%s', $locale->_('unknown')))->if($defaultField->handleEvent(atoum\runner::runStop, $test))->then->castToString($defaultField)->isEqualTo('unknown')->if($customField->handleEvent(atoum\runner::runStop, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf('%s', $locale->_('unknown')))->if($defaultField->handleEvent(atoum\test::runStop, $test))->then->castToString($defaultField)->isEqualTo(sprintf('%4.2f s', $runningDuration))->if($customField->handleEvent(atoum\test::runStop, $test))->then->castToString($customField)->isEqualTo($prompt . sprintf('%s', $durationColorizer->colorize(sprintf($locale->__('%4.2f s', '%4.2f s', $runningDuration), $runningDuration)))); }