diff --git a/.gitignore b/.gitignore index b386531f0..4486ead43 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/logs build/pdepend cache.properties phpunit.xml +/tests/_files/tmp /vendor /composer.lock /composer.phar diff --git a/src/CodeCoverage/Report/Text.php b/src/CodeCoverage/Report/Text.php index 174546fd8..d37a6d77c 100644 --- a/src/CodeCoverage/Report/Text.php +++ b/src/CodeCoverage/Report/Text.php @@ -223,9 +223,9 @@ protected function getCoverageColor($numberOfCoveredElements, $totalNumberOfElem return $this->colors['red']; } - protected function printCoverageCounts($numberOfCoveredElements, $totalNumberOfElements, $presicion) + protected function printCoverageCounts($numberOfCoveredElements, $totalNumberOfElements, $precision) { - $format = '%' . $presicion . 's'; + $format = '%' . $precision . 's'; return PHP_CodeCoverage_Util::percent( $numberOfCoveredElements, diff --git a/tests/PHP/CodeCoverage/FilterTest.php b/tests/PHP/CodeCoverage/FilterTest.php index c0e59e0ba..f39b95cdf 100644 --- a/tests/PHP/CodeCoverage/FilterTest.php +++ b/tests/PHP/CodeCoverage/FilterTest.php @@ -8,13 +8,7 @@ * file that was distributed with this source code. */ -if (!defined('TEST_FILES_PATH')) { - define( - 'TEST_FILES_PATH', - dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . - '_files' . DIRECTORY_SEPARATOR - ); -} +require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestCase.php'; /** * Tests for the PHP_CodeCoverage_Filter class. diff --git a/tests/PHP/CodeCoverage/Report/CloverTest.php b/tests/PHP/CodeCoverage/Report/CloverTest.php index 8d860bd2d..1b2174ee9 100644 --- a/tests/PHP/CodeCoverage/Report/CloverTest.php +++ b/tests/PHP/CodeCoverage/Report/CloverTest.php @@ -8,15 +8,7 @@ * file that was distributed with this source code. */ -if (!defined('TEST_FILES_PATH')) { - define( - 'TEST_FILES_PATH', - dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . - '_files' . DIRECTORY_SEPARATOR - ); -} - -require_once TEST_FILES_PATH . '../TestCase.php'; +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; /** * Tests for the PHP_CodeCoverage_Report_Clover class. diff --git a/tests/PHP/CodeCoverage/Report/Crap4jTest.php b/tests/PHP/CodeCoverage/Report/Crap4jTest.php new file mode 100644 index 000000000..2822aaea5 --- /dev/null +++ b/tests/PHP/CodeCoverage/Report/Crap4jTest.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; + +/** + * Tests for the PHP_CodeCoverage_Report_Crap4j class. + * + * @since Class available since Release 3.0.2 + */ +class PHP_CodeCoverage_Report_Crap4jTest extends PHP_CodeCoverage_TestCase +{ + /** + * @covers PHP_CodeCoverage_Report_Crap4j + */ + public function testForBankAccountTest() + { + $crap4j = new PHP_CodeCoverage_Report_Crap4j; + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'BankAccount-crap4j.xml', + $crap4j->process($this->getCoverageForBankAccount(), null, 'BankAccount') + ); + } + + /** + * @covers PHP_CodeCoverage_Report_Crap4j + */ + public function testForFileWithIgnoredLines() + { + $crap4j = new PHP_CodeCoverage_Report_Crap4j; + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'ignored-lines-crap4j.xml', + $crap4j->process($this->getCoverageForFileWithIgnoredLines(), null, 'CoverageForFileWithIgnoredLines') + ); + } + + /** + * @covers PHP_CodeCoverage_Report_Crap4j + */ + public function testForClassWithAnonymousFunction() + { + $crap4j = new PHP_CodeCoverage_Report_Crap4j; + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'class-with-anonymous-function-crap4j.xml', + $crap4j->process($this->getCoverageForClassWithAnonymousFunction(), null, 'CoverageForClassWithAnonymousFunction') + ); + } +} diff --git a/tests/PHP/CodeCoverage/Report/FactoryTest.php b/tests/PHP/CodeCoverage/Report/FactoryTest.php index 4c15f5c72..43616095d 100644 --- a/tests/PHP/CodeCoverage/Report/FactoryTest.php +++ b/tests/PHP/CodeCoverage/Report/FactoryTest.php @@ -8,15 +8,7 @@ * file that was distributed with this source code. */ -if (!defined('TEST_FILES_PATH')) { - define( - 'TEST_FILES_PATH', - dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . - '_files' . DIRECTORY_SEPARATOR - ); -} - -require_once TEST_FILES_PATH . '../TestCase.php'; +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; /** * Tests for the PHP_CodeCoverage_Report_Factory class. diff --git a/tests/PHP/CodeCoverage/Report/HTMLTest.php b/tests/PHP/CodeCoverage/Report/HTMLTest.php new file mode 100644 index 000000000..a58dcddd2 --- /dev/null +++ b/tests/PHP/CodeCoverage/Report/HTMLTest.php @@ -0,0 +1,112 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; + +/** + * Tests for the PHP_CodeCoverage_Report_HTML class. + * + * @since Class available since Release 3.0.2 + */ +class PHP_CodeCoverage_Report_HTMLTest extends PHP_CodeCoverage_TestCase +{ + static private $TEST_REPORT_PATH_SOURCE; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$TEST_REPORT_PATH_SOURCE = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'HTML'; + } + + protected function tearDown() + { + parent::tearDown(); + + $tmpFilesIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(self::$TEST_TMP_PATH, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($tmpFilesIterator as $path => $fileInfo) { + /* @var SplFileInfo $fileInfo */ + $pathname = $fileInfo->getPathname(); + $fileInfo->isDir() ? rmdir($pathname) : unlink($pathname); + } + } + + /** + * @covers PHP_CodeCoverage_Report_HTML + */ + public function testForBankAccountTest() + { + $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount'; + + $report = new PHP_CodeCoverage_Report_HTML; + $report->process($this->getCoverageForBankAccount(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @covers PHP_CodeCoverage_Report_HTML + */ + public function testForFileWithIgnoredLines() + { + $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines'; + + $report = new PHP_CodeCoverage_Report_HTML; + $report->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @covers PHP_CodeCoverage_Report_HTML + */ + public function testForClassWithAnonymousFunction() + { + $expectedFilesPath = + self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction'; + + $report = new PHP_CodeCoverage_Report_HTML; + $report->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @param string $expectedFilesPath + * @param string $actualFilesPath + */ + protected function assertFilesEquals($expectedFilesPath, $actualFilesPath) + { + $expectedFilesIterator = new FilesystemIterator($expectedFilesPath); + $actualFilesIterator = new RegexIterator(new FilesystemIterator($actualFilesPath), '/.html/'); + + $this->assertEquals( + iterator_count($expectedFilesIterator), + iterator_count($actualFilesIterator), + 'Generated files and expected files not match' + ); + foreach ($expectedFilesIterator as $path => $fileInfo) { + /* @var SplFileInfo $fileInfo */ + $filename = $fileInfo->getFilename(); + + $actualFile = $actualFilesPath . DIRECTORY_SEPARATOR . $filename; + + $this->assertFileExists($actualFile); + $this->assertStringMatchesFormatFile( + $fileInfo->getPathname(), + str_replace(PHP_EOL, "\n", file_get_contents($actualFile)), + "${filename} not match" + ); + } + } +} diff --git a/tests/PHP/CodeCoverage/Report/TextTest.php b/tests/PHP/CodeCoverage/Report/TextTest.php new file mode 100644 index 000000000..18e4125d8 --- /dev/null +++ b/tests/PHP/CodeCoverage/Report/TextTest.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; + +/** + * Tests for the PHP_CodeCoverage_Report_Text class. + * + * @since Class available since Release 3.0.2 + */ +class PHP_CodeCoverage_Report_TextTest extends PHP_CodeCoverage_TestCase +{ + /** + * @covers PHP_CodeCoverage_Report_Text + */ + public function testTextForBankAccountTest() + { + $text = new PHP_CodeCoverage_Report_Text(50, 90, false, false); + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'BankAccount-text.txt', + str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForBankAccount())) + ); + } + + /** + * @covers PHP_CodeCoverage_Report_Text + */ + public function testTextForFileWithIgnoredLines() + { + $text = new PHP_CodeCoverage_Report_Text(50, 90, false, false); + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'ignored-lines-text.txt', + str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForFileWithIgnoredLines())) + ); + } + + /** + * @covers PHP_CodeCoverage_Report_Text + */ + public function testTextForClassWithAnonymousFunction() + { + $text = new PHP_CodeCoverage_Report_Text(50, 90, false, false); + + $this->assertStringMatchesFormatFile( + TEST_FILES_PATH . 'class-with-anonymous-function-text.txt', + str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForClassWithAnonymousFunction())) + ); + } +} diff --git a/tests/PHP/CodeCoverage/Report/XMLTest.php b/tests/PHP/CodeCoverage/Report/XMLTest.php new file mode 100644 index 000000000..f35ef74bd --- /dev/null +++ b/tests/PHP/CodeCoverage/Report/XMLTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestCase.php'; + +/** + * Tests for the PHP_CodeCoverage_Report_XML class. + * + * @since Class available since Release 3.0.2 + */ +class PHP_CodeCoverage_Report_XMLTest extends PHP_CodeCoverage_TestCase +{ + static private $TEST_REPORT_PATH_SOURCE; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$TEST_REPORT_PATH_SOURCE = TEST_FILES_PATH . 'Report' . DIRECTORY_SEPARATOR . 'XML'; + } + + protected function tearDown() + { + parent::tearDown(); + + $tmpFilesIterator = new FilesystemIterator(self::$TEST_TMP_PATH); + foreach ($tmpFilesIterator as $path => $fileInfo) { + /* @var SplFileInfo $fileInfo */ + unlink($fileInfo->getPathname()); + } + } + + /** + * @covers PHP_CodeCoverage_Report_XML + */ + public function testForBankAccountTest() + { + $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForBankAccount'; + + $xml = new PHP_CodeCoverage_Report_XML; + $xml->process($this->getCoverageForBankAccount(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @covers PHP_CodeCoverage_Report_XML + */ + public function testForFileWithIgnoredLines() + { + $expectedFilesPath = self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForFileWithIgnoredLines'; + + $xml = new PHP_CodeCoverage_Report_XML; + $xml->process($this->getCoverageForFileWithIgnoredLines(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @covers PHP_CodeCoverage_Report_XML + */ + public function testForClassWithAnonymousFunction() + { + $expectedFilesPath = + self::$TEST_REPORT_PATH_SOURCE . DIRECTORY_SEPARATOR . 'CoverageForClassWithAnonymousFunction'; + + $xml = new PHP_CodeCoverage_Report_XML; + $xml->process($this->getCoverageForClassWithAnonymousFunction(), self::$TEST_TMP_PATH); + + $this->assertFilesEquals($expectedFilesPath, self::$TEST_TMP_PATH); + } + + /** + * @param string $expectedFilesPath + * @param string $actualFilesPath + */ + protected function assertFilesEquals($expectedFilesPath, $actualFilesPath) + { + $expectedFilesIterator = new FilesystemIterator($expectedFilesPath); + $actualFilesIterator = new FilesystemIterator($actualFilesPath); + + $this->assertEquals( + iterator_count($expectedFilesIterator), + iterator_count($actualFilesIterator), + 'Generated files and expected files not match' + ); + foreach ($expectedFilesIterator as $path => $fileInfo) { + /* @var SplFileInfo $fileInfo */ + $filename = $fileInfo->getFilename(); + + $actualFile = $actualFilesPath . DIRECTORY_SEPARATOR . $filename; + + $this->assertFileExists($actualFile); + $this->assertStringMatchesFormatFile( + $fileInfo->getPathname(), + file_get_contents($actualFile), + "${filename} not match" + ); + } + } +} diff --git a/tests/PHP/CodeCoverage/UtilTest.php b/tests/PHP/CodeCoverage/UtilTest.php index 0b4caea97..1cd8c20b8 100644 --- a/tests/PHP/CodeCoverage/UtilTest.php +++ b/tests/PHP/CodeCoverage/UtilTest.php @@ -8,6 +8,8 @@ * file that was distributed with this source code. */ +require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestCase.php'; + /** * Tests for the PHP_CodeCoverage_Util class. * diff --git a/tests/PHP/CodeCoverageTest.php b/tests/PHP/CodeCoverageTest.php index d6c8aa40c..b1d43f7d9 100644 --- a/tests/PHP/CodeCoverageTest.php +++ b/tests/PHP/CodeCoverageTest.php @@ -8,17 +8,7 @@ * file that was distributed with this source code. */ -if (!defined('TEST_FILES_PATH')) { - define( - 'TEST_FILES_PATH', - dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . - '_files' . DIRECTORY_SEPARATOR - ); -} - -require_once TEST_FILES_PATH . '../TestCase.php'; -require_once TEST_FILES_PATH . 'BankAccount.php'; -require_once TEST_FILES_PATH . 'BankAccountTest.php'; +require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestCase.php'; /** * Tests for the PHP_CodeCoverage class. diff --git a/tests/TestCase.php b/tests/TestCase.php index 01b0a5714..d03585cef 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,6 +8,10 @@ * file that was distributed with this source code. */ +if (!defined('TEST_FILES_PATH')) { + define('TEST_FILES_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR); +} + /** * Abstract base class for test case classes. * @@ -15,6 +19,13 @@ */ abstract class PHP_CodeCoverage_TestCase extends PHPUnit_Framework_TestCase { + static protected $TEST_TMP_PATH; + + public static function setUpBeforeClass() + { + self::$TEST_TMP_PATH = TEST_FILES_PATH . 'tmp'; + } + protected function getXdebugDataForBankAccount() { return [ @@ -70,6 +81,7 @@ protected function getXdebugDataForBankAccount() protected function getCoverageForBankAccount() { $data = $this->getXdebugDataForBankAccount(); + require_once TEST_FILES_PATH . 'BankAccountTest.php'; $stub = $this->getMock('PHP_CodeCoverage_Driver_Xdebug'); $stub->expects($this->any()) diff --git a/tests/_files/BankAccount-crap4j.xml b/tests/_files/BankAccount-crap4j.xml new file mode 100644 index 000000000..f2f56eabb --- /dev/null +++ b/tests/_files/BankAccount-crap4j.xml @@ -0,0 +1,59 @@ + + + BankAccount + %s + + Method Crap Stats + 4 + 0 + 0 + 9 + 0 + + + + global + BankAccount + getBalance + getBalance() + getBalance() + 1 + 1 + 100 + 0 + + + global + BankAccount + setBalance + setBalance($balance) + setBalance($balance) + 6 + 2 + 0 + 0 + + + global + BankAccount + depositMoney + depositMoney($balance) + depositMoney($balance) + 1 + 1 + 100 + 0 + + + global + BankAccount + withdrawMoney + withdrawMoney($balance) + withdrawMoney($balance) + 1 + 1 + 100 + 0 + + + diff --git a/tests/_files/BankAccount-text.txt b/tests/_files/BankAccount-text.txt new file mode 100644 index 000000000..892d83464 --- /dev/null +++ b/tests/_files/BankAccount-text.txt @@ -0,0 +1,12 @@ + + +Code Coverage Report: + %s + + Summary: + Classes: 0.00% (0/1) + Methods: 75.00% (3/4) + Lines: 50.00% (5/10) + +BankAccount + Methods: 75.00% ( 3/ 4) Lines: 50.00% ( 5/ 10) diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html b/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html new file mode 100644 index 000000000..a5dcd4c2b --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForBankAccount/BankAccount.php.html @@ -0,0 +1,267 @@ + + + + + Code Coverage for %s/BankAccount.php + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+
+ 75.00% covered (warning) +
+
+
75.00%
3 / 4
CRAP
+
+ 50.00% covered (danger) +
+
+
50.00%
5 / 10
BankAccount
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+
+ 75.00% covered (warning) +
+
+
75.00%
3 / 4
8.12
+
+ 50.00% covered (danger) +
+
+
50.00%
5 / 10
 getBalance
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
 setBalance
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
6
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 5
 depositMoney
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
 withdrawMoney
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<?php
class BankAccount
{
    protected $balance = 0;
    public function getBalance()
    {
        return $this->balance;
    }
    protected function setBalance($balance)
    {
        if ($balance >= 0) {
            $this->balance = $balance;
        } else {
            throw new RuntimeException;
        }
    }
    public function depositMoney($balance)
    {
        $this->setBalance($this->getBalance() + $balance);
        return $this->getBalance();
    }
    public function withdrawMoney($balance)
    {
        $this->setBalance($this->getBalance() - $balance);
        return $this->getBalance();
    }
}
+ +
+ + + + + + diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html new file mode 100644 index 000000000..651217a99 --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForBankAccount/dashboard.html @@ -0,0 +1,290 @@ + + + + + Dashboard for %s + + + + + + + +
+
+
+
+ +
+
+
+
+
+
+
+

Classes

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + + +
ClassCoverage
BankAccount50%
+
+
+
+

Project Risks

+
+ + + + + + + + + + + +
ClassCRAP
BankAccount8
+
+
+
+
+
+

Methods

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + + +
MethodCoverage
setBalance0%
+
+
+
+

Project Risks

+
+ + + + + + + + + + + +
MethodCRAP
setBalance6
+
+
+
+ +
+ + + + + + + + diff --git a/tests/_files/Report/HTML/CoverageForBankAccount/index.html b/tests/_files/Report/HTML/CoverageForBankAccount/index.html new file mode 100644 index 000000000..5c99c2e42 --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForBankAccount/index.html @@ -0,0 +1,119 @@ + + + + + Code Coverage for %s + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
+
+ 50.00% covered (danger) +
+
+
50.00%
5 / 10
+
+ 75.00% covered (warning) +
+
+
75.00%
3 / 4
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
BankAccount.php
+
+ 50.00% covered (danger) +
+
+
50.00%
5 / 10
+
+ 75.00% covered (warning) +
+
+
75.00%
3 / 4
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+ +
+ + + + + diff --git a/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/dashboard.html b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/dashboard.html new file mode 100644 index 000000000..229b1675a --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/dashboard.html @@ -0,0 +1,288 @@ + + + + + Dashboard for %s + + + + + + + +
+
+
+
+ +
+
+
+
+
+
+
+

Classes

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + + +
ClassCoverage
CoveredClassWithAnonymousFunctionInStaticMethod87%
+
+
+
+

Project Risks

+
+ + + + + + + + + + +
ClassCRAP
+
+
+
+
+
+

Methods

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + + +
MethodCoverage
runAnonymous66%
+
+
+
+

Project Risks

+
+ + + + + + + + + + +
MethodCRAP
+
+
+
+ +
+ + + + + + + + diff --git a/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/index.html b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/index.html new file mode 100644 index 000000000..ace676be4 --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/index.html @@ -0,0 +1,119 @@ + + + + + Code Coverage for %s + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
+
+ 87.50% covered (warning) +
+
+
87.50%
7 / 8
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
source_with_class_and_anonymous_function.php
+
+ 87.50% covered (warning) +
+
+
87.50%
7 / 8
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+ +
+ + + + + diff --git a/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html new file mode 100644 index 000000000..ce90096b9 --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.html @@ -0,0 +1,211 @@ + + + + + Code Coverage for %s/source_with_class_and_anonymous_function.php + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
CRAP
+
+ 87.50% covered (warning) +
+
+
87.50%
7 / 8
CoveredClassWithAnonymousFunctionInStaticMethod
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
2.01
+
+ 87.50% covered (warning) +
+
+
87.50%
7 / 8
 runAnonymous
+
+ 0.00% covered (danger) +
+
+
0.00%
0 / 1
1.04
+
+ 66.67% covered (warning) +
+
+
66.67%
2 / 3
 anonymous function
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
+ + + + + + + + + + + + + + + + + + + + + + + +
<?php
class CoveredClassWithAnonymousFunctionInStaticMethod
{
    public static function runAnonymous()
    {
        $filter = ['abc124', 'abc123', '123'];
        array_walk(
            $filter,
            function (&$val, $key) {
                $val = preg_replace('|[^0-9]|', '', $val);
            }
        );
        // Should be covered
        $extravar = true;
    }
}
+ +
+ + + + + + diff --git a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/dashboard.html b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/dashboard.html new file mode 100644 index 000000000..54deaeaba --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/dashboard.html @@ -0,0 +1,286 @@ + + + + + Dashboard for %s + + + + + + + +
+
+
+
+ +
+
+
+
+
+
+
+

Classes

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + +
ClassCoverage
+
+
+
+

Project Risks

+
+ + + + + + + + + + +
ClassCRAP
+
+
+
+
+
+

Methods

+
+
+
+
+

Coverage Distribution

+
+ +
+
+
+

Complexity

+
+ +
+
+
+
+
+

Insufficient Coverage

+
+ + + + + + + + + + +
MethodCoverage
+
+
+
+

Project Risks

+
+ + + + + + + + + + +
MethodCRAP
+
+
+
+ +
+ + + + + + + + diff --git a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html new file mode 100644 index 000000000..2687444ff --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/index.html @@ -0,0 +1,119 @@ + + + + + Code Coverage for %s + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
source_with_ignore.php
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
+ +
+ + + + + diff --git a/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html new file mode 100644 index 000000000..251b5c309 --- /dev/null +++ b/tests/_files/Report/HTML/CoverageForFileWithIgnoredLines/source_with_ignore.php.html @@ -0,0 +1,279 @@ + + + + + Code Coverage for %s/source_with_ignore.php + + + + + + +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
+
+ 100.00% covered (success) +
+
+
100.00%
2 / 2
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
CRAP
+
+ 50.00% covered (danger) +
+
+
50.00%
1 / 2
baz
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
0
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
Foo
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
 bar
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
Bar
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
 foo
+
+ 100.00% covered (success) +
+
+
100.00%
1 / 1
1
+
+ 100.00% covered (success) +
+
+
100.00%
0 / 0
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<?php
if ($neverHappens) {
    // @codeCoverageIgnoreStart
    print '*';
    // @codeCoverageIgnoreEnd
}
/**
 * @codeCoverageIgnore
 */
class Foo
{
    public function bar()
    {
    }
}
class Bar
{
    /**
     * @codeCoverageIgnore
     */
    public function foo()
    {
    }
}
function baz()
{
    print '*'; // @codeCoverageIgnore
}
interface Bor
{
    public function foo();
}
+ +
+ + + + + + diff --git a/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml new file mode 100644 index 000000000..d5c5d2e5f --- /dev/null +++ b/tests/_files/Report/XML/CoverageForBankAccount/BankAccount.php.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/Report/XML/CoverageForBankAccount/index.xml b/tests/_files/Report/XML/CoverageForBankAccount/index.xml new file mode 100644 index 000000000..27fc5b405 --- /dev/null +++ b/tests/_files/Report/XML/CoverageForBankAccount/index.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml new file mode 100644 index 000000000..6f9cd19c4 --- /dev/null +++ b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/index.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml new file mode 100644 index 000000000..d42452474 --- /dev/null +++ b/tests/_files/Report/XML/CoverageForClassWithAnonymousFunction/source_with_class_and_anonymous_function.php.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml new file mode 100644 index 000000000..35c0745d5 --- /dev/null +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/index.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml new file mode 100644 index 000000000..509990f87 --- /dev/null +++ b/tests/_files/Report/XML/CoverageForFileWithIgnoredLines/source_with_ignore.php.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/_files/class-with-anonymous-function-crap4j.xml b/tests/_files/class-with-anonymous-function-crap4j.xml new file mode 100644 index 000000000..696496dab --- /dev/null +++ b/tests/_files/class-with-anonymous-function-crap4j.xml @@ -0,0 +1,37 @@ + + + CoverageForClassWithAnonymousFunction + %s + + Method Crap Stats + 2 + 0 + 0 + 2.04 + 0 + + + + global + CoveredClassWithAnonymousFunctionInStaticMethod + runAnonymous + runAnonymous() + runAnonymous() + 1.04 + 1 + 66.67 + 0 + + + global + CoveredClassWithAnonymousFunctionInStaticMethod + anonymous function + anonymous function (&$val, $key) + anonymous function (&$val, $key) + 1 + 1 + 100 + 0 + + + diff --git a/tests/_files/class-with-anonymous-function-text.txt b/tests/_files/class-with-anonymous-function-text.txt new file mode 100644 index 000000000..0eb257e5f --- /dev/null +++ b/tests/_files/class-with-anonymous-function-text.txt @@ -0,0 +1,12 @@ + + +Code Coverage Report: + %s + + Summary: + Classes: 0.00% (0/1) + Methods: 50.00% (1/2) + Lines: 87.50% (7/8) + +CoveredClassWithAnonymousFunctionInStaticMethod + Methods: 50.00% ( 1/ 2) Lines: 80.00% ( 4/ 5) diff --git a/tests/_files/ignored-lines-crap4j.xml b/tests/_files/ignored-lines-crap4j.xml new file mode 100644 index 000000000..2607b59ac --- /dev/null +++ b/tests/_files/ignored-lines-crap4j.xml @@ -0,0 +1,37 @@ + + + CoverageForFileWithIgnoredLines + %s + + Method Crap Stats + 2 + 0 + 0 + 2 + 0 + + + + global + Foo + bar + bar() + bar() + 1 + 1 + 100 + 0 + + + global + Bar + foo + foo() + foo() + 1 + 1 + 100 + 0 + + + diff --git a/tests/_files/ignored-lines-text.txt b/tests/_files/ignored-lines-text.txt new file mode 100644 index 000000000..428303873 --- /dev/null +++ b/tests/_files/ignored-lines-text.txt @@ -0,0 +1,10 @@ + + +Code Coverage Report: + %s + + Summary: + Classes: 100.00% (2/2) + Methods: (0/0) + Lines: 50.00% (1/2) +