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":'); }
<?php use mageekguy\atoum\reports; $runner->addTestsFromDirectory(__DIR__ . '/tests/units/classes')->disallowUsageOfUndefinedMethodInMock(); $runner->getScore()->getCoverage()->excludeDirectory(__DIR__ . '/tests/units/mock'); $travis = getenv('TRAVIS'); if ($travis) { $script->addDefaultReport(); $coverallsToken = getenv('COVERALLS_REPO_TOKEN'); if ($coverallsToken) { $coverallsReport = new reports\asynchronous\coveralls('classes', $coverallsToken); $defaultFinder = $coverallsReport->getBranchFinder(); $coverallsReport->setBranchFinder(function () use($defaultFinder) { if (($branch = getenv('TRAVIS_BRANCH')) === false) { $branch = $defaultFinder(); } return $branch; })->setServiceName('travis-ci')->setServiceJobId(getenv('TRAVIS_JOB_ID'))->addDefaultWriter(); $runner->addReport($coverallsReport); } }