Example #1
0
 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);
 }
Example #2
0
 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":');
 }
Example #3
0
 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);
 }