Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:jubianchi/atoum

  • Loading branch information...
commit afbdead23fe9cabfd49e2e065b71508361671f59 2 parents a22c2f7 + 125c2b2
@ludofleury ludofleury authored
View
293 classes/reports/asynchronous/clover.php
@@ -0,0 +1,293 @@
+<?php
+
+namespace mageekguy\atoum\reports\asynchronous;
+
+use
+ mageekguy\atoum,
+ mageekguy\atoum\exceptions,
+ mageekguy\atoum\report\fields,
+ mageekguy\atoum\score
+;
+
+class clover extends atoum\reports\asynchronous {
+ const defaultTitle = 'atoum code coverage';
+ const defaultPackage = 'atoumCodeCoverage';
+ const lineTypeMethod = 'method';
+ const lineTypeStatement = 'stmt';
+ const lineTypeConditional = 'cond';
+
+ private $package;
+
+ protected $score = null;
+ protected $loc = 0;
+ protected $coveredLoc = 0;
+ protected $methods = 0;
+ protected $coveredMethods = 0;
+ protected $classes = 0;
+
+ public function __construct(atoum\adapter $adapter = null)
+ {
+ parent::__construct(null, $adapter);
+
+ if ($this->getAdapter()->extension_loaded('libxml') === false)
+ {
+ throw new exceptions\runtime('libxml PHP extension is mandatory for clover report');
+ }
+ }
+
+ public function getTitle()
+ {
+ return $this->title ?: self::defaultTitle;
+ }
+
+ public function getPackage()
+ {
+ return $this->package ?: self::defaultPackage;
+ }
+
+ public function setPackage($package)
+ {
+ $this->package = $package;
+
+ return $this;
+ }
+
+ public function handleEvent($event, atoum\observable $observable)
+ {
+ $this->score = ($event !== atoum\runner::runStop) ? null : $observable->getScore();
+
+ return parent::handleEvent($event, $observable);
+ }
+
+ public function build($event)
+ {
+ if ($event === atoum\runner::runStop)
+ {
+ $document = new \DOMDocument('1.0', 'UTF-8');
+ $document->formatOutput = true;
+ $document->appendChild($this->makeRootElement($document, $this->score->getCoverage()));
+
+ $this->string = $document->saveXML();
+ }
+
+ return $this;
+ }
+
+ public function makeRootElement(\DOMDocument $document, score\coverage $coverage)
+ {
+ $root = $document->createElement('coverage');
+ $root->setAttribute('generated', $this->getAdapter()->time());
+ $root->setAttribute('clover', $this->getAdapter()->uniqid());
+
+ $root->appendChild($this->makeProjectElement($document, $coverage));
+
+ return $root;
+ }
+
+ public function makeProjectElement(\DOMDocument $document, score\coverage $coverage)
+ {
+ $project = $document->createElement('project');
+ $project->setAttribute('timestamp', $this->getAdapter()->time());
+ $project->setAttribute('name', $this->getTitle());
+
+ $project->appendChild($this->makePackageElement($document, $coverage));
+ $project->appendChild($this->makeProjectMetricsElement($document, sizeof($coverage->getClasses())));
+
+ return $project;
+ }
+
+ public function makeProjectMetricsElement(\DOMDocument $document, $files)
+ {
+ $metrics = $this->makePackageMetricsElement($document, $files);
+ $metrics->setAttribute('packages', 1);
+
+ return $metrics;
+ }
+
+ public function makePackageElement(\DOMDocument $document, score\coverage $coverage)
+ {
+ $package = $document->createElement('package');
+ $package->setAttribute('name', $this->getPackage());
+
+ foreach ($coverage->getClasses() as $class => $file)
+ {
+ $package->appendChild($this->makeFileElement($document, $file, $class, $coverage->getCoverageForClass($class)));
+ }
+
+ $package->appendChild($this->makePackageMetricsElement($document, sizeof($coverage->getClasses())));
+
+ return $package;
+ }
+
+ public function makePackageMetricsElement(\DOMDocument $document, $files)
+ {
+ $metrics = $this->makeFileMetricsElement($document, $this->loc, $this->coveredLoc, $this->methods, $this->coveredMethods, 1);
+ $metrics->setAttribute('files', $files);
+
+ return $metrics;
+ }
+
+ public function makeFileElement(\DOMDocument $document, $filename, $class, array $coverage)
+ {
+ $file = $document->createElement('file');
+ $file->setAttribute('name', basename($filename));
+ $file->setAttribute('path', $filename);
+
+ $methods = count($coverage);
+ $coveredMethods = 0;
+ $totalLines = 0;
+ $coveredLines = 0;
+
+ foreach ($coverage as $lines)
+ {
+ if (sizeof($lines) > 0)
+ {
+ ++$coveredMethods;
+
+ foreach ($lines as $lineNumber => $cover)
+ {
+ if ($cover >= -1)
+ {
+ $totalLines++;
+ }
+
+ if ($cover === 1)
+ {
+ $coveredLines++;
+ $file->appendChild($this->makeLineElement($document, $lineNumber));
+ }
+ }
+ }
+ }
+
+ $this
+ ->addLoc($totalLines)
+ ->addCoveredLoc($coveredLines)
+ ->addMethod($methods)
+ ->addCoveredMethod($coveredMethods)
+ ->addClasses(1)
+ ;
+
+ $file->appendChild($this->makeClassElement($document, $class, $coverage));
+ $file->appendChild($this->makeFileMetricsElement($document, $totalLines, $coveredLines, $methods, $coveredMethods, $this->classes));
+
+ return $file;
+ }
+
+ public function makeFileMetricsElement(\DOMDocument $document, $loc, $cloc, $methods, $coveredMethods, $classes)
+ {
+ $metrics = $this->makeClassMetricsElement($document, $loc, $cloc, $methods, $coveredMethods);
+ $metrics->setAttribute('classes', $classes);
+ $metrics->setAttribute('loc', $loc);
+ $metrics->setAttribute('ncloc', $loc);
+
+ return $metrics;
+ }
+
+ public function makeClassElement(\DOMDocument $document, $classname, array $coverage)
+ {
+ $class = $document->createElement('class');
+ $class->setAttribute('name', basename(str_replace('\\', DIRECTORY_SEPARATOR, $classname)));
+
+ $methods = count($coverage);
+ $coveredMethods = 0;
+ $totalLines = 0;
+ $coveredLines = 0;
+ foreach ($coverage as $lines)
+ {
+ if (sizeof($lines) > 0)
+ {
+ ++$coveredMethods;
+ }
+
+ foreach ($lines as $cover)
+ {
+ if ($cover >= -1)
+ {
+ $totalLines++;
+ }
+
+ if ($cover === 1)
+ {
+ $coveredLines++;
+ }
+ }
+ }
+
+ $class->appendChild($this->makeClassMetricsElement($document, $totalLines, $coveredLines, $methods, $coveredMethods));
+
+ return $class;
+ }
+
+ public function makeClassMetricsElement(\DOMDocument $document, $loc, $cloc, $methods, $cmethods)
+ {
+ $metrics = $document->createElement('metrics');
+ $metrics->setAttribute('complexity', 0);
+ $metrics->setAttribute('elements', $loc);
+ $metrics->setAttribute('coveredelements', $cloc);
+ $metrics->setAttribute('conditionals', 0);
+ $metrics->setAttribute('coveredconditionals', 0);
+ $metrics->setAttribute('statements', $loc);
+ $metrics->setAttribute('coveredstatements', $cloc);
+ $metrics->setAttribute('methods', $methods);
+ $metrics->setAttribute('coveredmethods', $cmethods);
+ $metrics->setAttribute('testduration', 0);
+ $metrics->setAttribute('testfailures', 0);
+ $metrics->setAttribute('testpasses', 0);
+ $metrics->setAttribute('testruns', 0);
+
+ return $metrics;
+ }
+
+ public function makeLineElement(\DOMDocument $document, $linenum)
+ {
+ $line = $document->createElement('line');
+ $line->setAttribute('num', $linenum);
+ $line->setAttribute('type', self::lineTypeStatement);
+ $line->setAttribute('complexity', 0);
+ $line->setAttribute('count', 1);
+ $line->setAttribute('falsecount', 0);
+ $line->setAttribute('truecount', 0);
+ $line->setAttribute('signature', '');
+ $line->setAttribute('testduration', 0);
+ $line->setAttribute('testsuccess', 0);
+
+ return $line;
+ }
+
+
+ protected function addLoc($count)
+ {
+ $this->loc += $count;
+
+ return $this;
+ }
+
+ protected function addCoveredLoc($count)
+ {
+ $this->coveredLoc += $count;
+
+ return $this;
+ }
+
+ protected function addMethod($count)
+ {
+ $this->methods += $count;
+
+ return $this;
+ }
+
+ protected function addCoveredMethod($count)
+ {
+ $this->coveredMethods += $count;
+
+ return $this;
+ }
+
+ protected function addClasses($count)
+ {
+ $this->classes += $count;
+
+ return $this;
+ }
+}
View
24 classes/score/coverage.php
@@ -225,6 +225,18 @@ public function getValueForClass($class)
return $value;
}
+ public function getCoverageForClass($class)
+ {
+ $class = (string) $class;
+
+ if(isset($this->methods[$class]) === false)
+ {
+ throw new exceptions\logic\invalidArgument('Class \'' . $class . '\' does not exist');
+ }
+
+ return ($this->isInExcludedClasses($class) ? array() : $this->methods[$class]);
+ }
+
public function getValueForMethod($class, $method)
{
$value = null;
@@ -256,6 +268,18 @@ public function getValueForMethod($class, $method)
return $value;
}
+ public function getCoverageForMethod($class, $method)
+ {
+ $class = $this->getCoverageForClass($class);
+
+ if(isset($class[$method]) === false)
+ {
+ throw new exceptions\logic\invalidArgument('Method \'' . $method . '\' does not exist');
+ }
+
+ return $class[$method];
+ }
+
public function excludeClass($class)
{
$class = (string) $class;
View
19 resources/configurations/runner/clover.php.dist
@@ -0,0 +1,19 @@
+<?php
+
+/*
+Sample atoum configuration file to have code coverage in clover format.
+Do "php path/to/test/file -c path/to/this/file" or "php path/to/atoum/scripts/runner.php -c path/to/this/file -f path/to/test/file" to use it.
+*/
+
+use \mageekguy\atoum;
+
+/*
+Please replace in next line /path/to/destination/directory/atoum.coverage.xml by your output file for clover report.
+*/
+$cloverWriter = new atoum\writers\file('/path/to/destination/directory/atoum.coverage.xml');
+
+$cloverReport = new atoum\reports\asynchronous\clover();
+
+$runner->addReport($cloverReport);
+
+?>
View
312 tests/units/classes/reports/asynchronous/clover.php
@@ -0,0 +1,312 @@
+<?php
+
+namespace mageekguy\atoum\tests\units\reports\asynchronous;
+
+use
+ mageekguy\atoum,
+ mageekguy\atoum\report,
+ mageekguy\atoum\score,
+ ageekguy\atoum\asserter\exception,
+ mageekguy\atoum\reports\asynchronous as reports
+;
+
+require_once __DIR__ . '/../../../runner.php';
+
+class clover extends atoum\test
+{
+ public function testClass()
+ {
+ $this
+ ->testedClass->isSubclassOf('mageekguy\atoum\reports\asynchronous')
+ ;
+ }
+
+ public function testClassConstants()
+ {
+ $this
+ ->string(reports\clover::defaultTitle)->isEqualTo('atoum code coverage')
+ ->string(reports\clover::defaultPackage)->isEqualTo('atoumCodeCoverage')
+ ->string(reports\clover::lineTypeMethod)->isEqualTo('method')
+ ->string(reports\clover::lineTypeStatement)->isEqualTo('stmt')
+ ->string(reports\clover::lineTypeConditional)->isEqualTo('cond')
+ ;
+ }
+
+ public function test__construct()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->array($report->getFields(atoum\runner::runStart))->isEmpty()
+ ->object($report->getAdapter())->isInstanceOf('mageekguy\atoum\adapter')
+ ;
+
+ $adapter = new atoum\test\adapter();
+ $adapter->extension_loaded = true;
+
+ $this
+ ->if($report = new reports\clover($adapter))
+ ->then
+ ->array($report->getFields())->isEmpty()
+ ->object($report->getAdapter())->isIdenticalTo($adapter)
+ ->adapter($adapter)->call('extension_loaded')->withArguments('libxml')->once()
+ ;
+
+ $adapter->extension_loaded = false;
+
+ $this
+ ->exception(function() use ($adapter) {
+ $report = new reports\clover($adapter);
+ }
+ )
+ ->isInstanceOf('mageekguy\atoum\exceptions\runtime')
+ ->hasMessage('libxml PHP extension is mandatory for clover report')
+ ;
+ }
+
+ public function testSetAdapter()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->object($report->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($report)
+ ->object($report->getAdapter())->isIdenticalTo($adapter)
+ ;
+ }
+
+ public function testHandleEvent()
+ {
+ $this
+ ->if($report = new reports\clover())
+ ->then
+ ->variable($report->getTitle())->isEqualTo('atoum code coverage')
+ ->variable($report->getPackage())->isEqualTo('atoumCodeCoverage')
+ ->castToString($report)->isEmpty()
+ ->string($report->handleEvent(atoum\runner::runStop, new atoum\runner())->getTitle())->isEqualTo(reports\clover::defaultTitle)
+ ->castToString($report)->isNotEmpty()
+ ;
+
+ $report = new reports\clover();
+
+ $this
+ ->string($report->setTitle($title = uniqid())->handleEvent(atoum\runner::runStop, new atoum\runner())->getTitle())
+ ->isEqualTo($title);
+
+ $report = new reports\clover();
+
+ $writer = new \mock\mageekguy\atoum\writers\file();
+ $writer->getMockController()->write = function($something) use ($writer) { return $writer; };
+
+ $this
+ ->when(function() use ($report, $writer) { $report->addWriter($writer)->handleEvent(atoum\runner::runStop, new \mageekguy\atoum\runner()); })
+ ->mock($writer)->call('writeAsynchronousReport')->withArguments($report)->once()
+ ;
+ }
+
+ public function testSetTitle()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->object($report->setTitle($title = uniqid()))->isIdenticalTo($report)
+ ->string($report->getTitle())->isEqualTo($title)
+ ;
+ }
+
+ public function testSetPackage()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->object($report->setPackage($package = uniqid()))->isIdenticalTo($report)
+ ->string($report->getPackage())->isEqualTo($package)
+ ;
+ }
+
+ public function testBuild()
+ {
+ $adapter = new atoum\test\adapter();
+ $adapter->time = $generated = time();
+ $adapter->uniqid = $clover = uniqid();
+
+ $observable = new \mock\mageekguy\atoum\runner();
+ $observable->getScore = new score\coverage();
+
+ $report = new reports\clover($adapter);
+
+ $this
+ ->if($report->handleEvent(atoum\runner::runStop, $observable))
+ ->then
+ ->castToString($report)->isEqualTo(<<<XML
+<?xml version="1.0" encoding="UTF-8"?>
+<coverage generated="$generated" clover="$clover">
+ <project timestamp="$generated" name="atoum code coverage">
+ <package name="atoumCodeCoverage">
+ <metrics complexity="0" elements="0" coveredelements="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" methods="0" coveredmethods="0" testduration="0" testfailures="0" testpasses="0" testruns="0" classes="1" loc="0" ncloc="0" files="0"/>
+ </package>
+ <metrics complexity="0" elements="0" coveredelements="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" methods="0" coveredmethods="0" testduration="0" testfailures="0" testpasses="0" testruns="0" classes="1" loc="0" ncloc="0" files="0" packages="1"/>
+ </project>
+</coverage>
+
+XML
+ )
+ ;
+ }
+
+ public function testMakeRootElement()
+ {
+ $adapter = new atoum\test\adapter();
+ $adapter->time = $generated = time();
+ $adapter->uniqid = $clover = uniqid();
+
+ $report = new reports\clover($adapter);
+
+ $this
+ ->object($element = $report->makeRootElement(new \DOMDocument(), new score\coverage()))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('coverage')
+ ->string($element->getAttribute('generated'))->isEqualTo($generated)
+ ->string($element->getAttribute('clover'))->isEqualTo($clover)
+ ;
+ }
+
+ public function testMakeProjectElement()
+ {
+ $adapter = new atoum\test\adapter();
+ $adapter->time = $timestamp = time();
+
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+ $report->setAdapter($adapter);
+
+ $this
+ ->object($element = $report->makeProjectElement($document = new \DOMDocument(), $score = new score\coverage()))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('project')
+ ->string($element->getAttribute('timestamp'))->isEqualTo($timestamp)
+ ->string($element->getAttribute('name'))->isEqualTo('atoum code coverage')
+ ->mock($report)
+ ->call('getTitle')->once()
+ ->call('makeProjectMetricsElement')->once()->withArguments($document, 0)
+ ->call('makePackageElement')->once()->withArguments($document, $score)
+ ;
+ }
+
+ public function testMakeProjectMetricsElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makeProjectMetricsElement($document = new \DOMDocument(), $files = rand(0, 10)))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('metrics')
+ ->string($element->getAttribute('packages'))->isEqualTo('1')
+ ->mock($report)
+ ->call('makePackageMetricsElement')->once()->withArguments($document, $files)
+ ;
+ }
+
+ public function testMakePackageElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makePackageElement($document = new \DOMDocument(), $score = new score\coverage()))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('package')
+ ->string($element->getAttribute('name'))->isEqualTo('atoumCodeCoverage')
+ ->mock($report)
+ ->call('getPackage')->once()
+ ->call('makePackageMetricsElement')->once()->withArguments($document, 0)
+ ->call('makeFileElement')->never();
+ ;
+ }
+
+ public function testMakePackageMetricsElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makePackageMetricsElement($document = new \DOMDocument(), $files = rand(0, 10)))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('metrics')
+ ->string($element->getAttribute('files'))->isEqualTo($files)
+ ->mock($report)
+ ->call('makeFileMetricsElement')->once()->withArguments($document, 0, 0, 0, 0, 1)
+ ;
+ }
+
+ public function testMakeFileElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makeFileElement($document = new \DOMDocument(), $filename = '/foo/bar.php', $class = 'bar', array()))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('file')
+ ->string($element->getAttribute('name'))->isEqualTo('bar.php')
+ ->string($element->getAttribute('path'))->isEqualTo($filename)
+ ->mock($report)
+ ->call('makeLineElement')->never()
+ ->call('makeClassElement')->once()->withArguments($document, $class, array())
+ ->call('makeFileMetricsElement')->once()->withArguments($document, 0, 0, 0, 0, 0)
+ ;
+ }
+
+ public function testMakeFileMetricsElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makeFileMetricsElement($document = new \DOMDocument(), $loc = rand(0, 10), $cloc = rand(0, 10), $methods = rand(0, 10), $cmethods = rand(0, 10), $classes = rand(0, 10)))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('metrics')
+ ->string($element->getAttribute('classes'))->isEqualTo($classes)
+ ->string($element->getAttribute('loc'))->isEqualTo($loc)
+ ->string($element->getAttribute('ncloc'))->isEqualTo($loc)
+ ->mock($report)
+ ->call('makeClassMetricsElement')->once()->withArguments($document, $loc, $cloc, $methods, $cmethods)
+ ;
+ }
+
+ public function testMakeClassElement()
+ {
+ $report = new \mock\mageekguy\atoum\reports\asynchronous\clover();
+
+ $this
+ ->object($element = $report->makeClassElement($document = new \DOMDocument(), $class = uniqid(), array()))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('class')
+ ->string($element->getAttribute('name'))->isEqualTo($class)
+ ->mock($report)
+ ->call('makeClassMetricsElement')->once()->withArguments($document, 0, 0, 0, 0, 0)
+ ;
+ }
+
+ public function testMakeClassMetricsElement()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->object($element = $report->makeClassMetricsElement($document = new \DOMDocument(), $loc = rand(0, 10), $cloc = rand(0, 10), $methods = rand(0, 10), $cmethods = rand(0, 10)))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('metrics')
+ ->string($element->getAttribute('complexity'))->isEqualTo(0)
+ ->string($element->getAttribute('elements'))->isEqualTo($loc)
+ ->string($element->getAttribute('coveredelements'))->isEqualTo($cloc)
+ ->string($element->getAttribute('conditionals'))->isEqualTo(0)
+ ->string($element->getAttribute('coveredconditionals'))->isEqualTo(0)
+ ->string($element->getAttribute('statements'))->isEqualTo($loc)
+ ->string($element->getAttribute('coveredstatements'))->isEqualTo($cloc)
+ ->string($element->getAttribute('methods'))->isEqualTo($methods)
+ ->string($element->getAttribute('coveredmethods'))->isEqualTo($cmethods)
+ ->string($element->getAttribute('testduration'))->isEqualTo(0)
+ ->string($element->getAttribute('testfailures'))->isEqualTo(0)
+ ->string($element->getAttribute('testpasses'))->isEqualTo(0)
+ ->string($element->getAttribute('testruns'))->isEqualTo(0)
+ ;
+ }
+
+ public function testMakeLineElement()
+ {
+ $report = new reports\clover();
+
+ $this
+ ->object($element = $report->makeLineElement($document = new \DOMDocument(), $linenum = rand(0, 10)))->isInstanceOf('\DOMElement')
+ ->string($element->tagName)->isEqualTo('line')
+ ->string($element->getAttribute('num'))->isEqualTo($linenum)
+ ;
+ }
+}
+
+?>
View
149 tests/units/classes/score/coverage.php
@@ -795,6 +795,82 @@ public function testGetValueForClass()
;
}
+ public function testGetCoverageForClass()
+ {
+ $coverage = new score\coverage();
+
+ $this
+ ->exception(function() use ($coverage) {
+ $coverage->getCoverageForClass(uniqid());
+ })
+ ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument');
+ ;
+
+ $classController = new mock\controller();
+ $classController->__construct = function() {};
+ $classController->getName = function() use (& $className) { return $className; };
+ $classController->getFileName = function() use (& $classFile) { return $classFile; };
+
+ $class = new \mock\reflectionClass(uniqid(), $classController);
+
+ $methodController = new mock\controller();
+ $methodController->__construct = function() {};
+ $methodController->getName = function() use (& $methodName) { return $methodName; };
+ $methodController->isAbstract = false;
+ $methodController->getFileName = function() use (& $classFile) { return $classFile; };
+ $methodController->getDeclaringClass = function() use ($class) { return $class; };
+ $methodController->getStartLine = 4;
+ $methodController->getEndLine = 8;
+
+ $classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController));
+
+ $classFile = uniqid();
+ $className = uniqid();
+ $methodName = uniqid();
+
+ $xdebugData = array(
+ $classFile =>
+ array(
+ 3 => -2,
+ 4 => 1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -2,
+ 9 => -1
+ ),
+ uniqid() =>
+ array(
+ 5 => 2,
+ 6 => 3,
+ 7 => 4,
+ 8 => 3,
+ 9 => 2
+ )
+ );
+
+ $expected = array(
+ $methodName =>
+ array(
+ 4 => 1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -2,
+ )
+ );
+
+ $coverage
+ ->setReflectionClassInjector(function($className) use ($class) { return $class; })
+ ;
+
+ $coverage->addXdebugDataForTest($this, $xdebugData);
+
+ $this
+ ->array($coverage->getCoverageForClass($className))->isEqualTo($expected)
+ ;
+ }
+
public function testGetValueForMethod()
{
$coverage = new score\coverage();
@@ -946,6 +1022,79 @@ public function testGetValueForMethod()
;
}
+ public function testGetCoverageForMethod()
+ {
+ $coverage = new score\coverage();
+
+ $this
+ ->exception(function() use ($coverage) {
+ $coverage->getCoverageForClass(uniqid());
+ })
+ ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument');
+ ;
+
+ $classController = new mock\controller();
+ $classController->__construct = function() {};
+ $classController->getName = function() use (& $className) { return $className; };
+ $classController->getFileName = function() use (& $classFile) { return $classFile; };
+
+ $class = new \mock\reflectionClass(uniqid(), $classController);
+
+ $methodController = new mock\controller();
+ $methodController->__construct = function() {};
+ $methodController->getName = function() use (& $methodName) { return $methodName; };
+ $methodController->isAbstract = false;
+ $methodController->getFileName = function() use (& $classFile) { return $classFile; };
+ $methodController->getDeclaringClass = function() use ($class) { return $class; };
+ $methodController->getStartLine = 4;
+ $methodController->getEndLine = 8;
+
+ $classController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $methodController));
+
+ $classFile = uniqid();
+ $className = uniqid();
+ $methodName = uniqid();
+
+ $xdebugData = array(
+ $classFile =>
+ array(
+ 3 => -2,
+ 4 => 1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -2,
+ 9 => -1
+ ),
+ uniqid() =>
+ array(
+ 5 => 2,
+ 6 => 3,
+ 7 => 4,
+ 8 => 3,
+ 9 => 2
+ )
+ );
+
+ $expected = array(
+ 4 => 1,
+ 5 => -1,
+ 6 => -1,
+ 7 => -1,
+ 8 => -2,
+ );
+
+ $coverage
+ ->setReflectionClassInjector(function($className) use ($class) { return $class; })
+ ;
+
+ $coverage->addXdebugDataForTest($this, $xdebugData);
+
+ $this
+ ->array($coverage->getCoverageForMethod($className, $methodName))->isEqualTo($expected)
+ ;
+ }
+
public function testExcludeClass()
{
$this->assert
Please sign in to comment.
Something went wrong with that request. Please try again.