Update v1.0.6

This commit is contained in:
Bhanu Slathia
2016-02-16 23:22:09 +05:30
parent 62d04a0372
commit c710c20b9e
7620 changed files with 244752 additions and 1070312 deletions

View File

@@ -1,281 +0,0 @@
<?php
/*
* This file is part of the PHP_CodeCoverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* 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
);
}
/**
* Tests for the PHP_CodeCoverage_Filter class.
*
* @since Class available since Release 1.0.0
*/
class PHP_CodeCoverage_FilterTest extends PHPUnit_Framework_TestCase
{
protected $filter;
protected $files;
protected function setUp()
{
$this->filter = unserialize('O:23:"PHP_CodeCoverage_Filter":0:{}');
$this->files = array(
TEST_FILES_PATH . 'BankAccount.php',
TEST_FILES_PATH . 'BankAccountTest.php',
TEST_FILES_PATH . 'CoverageClassExtendedTest.php',
TEST_FILES_PATH . 'CoverageClassTest.php',
TEST_FILES_PATH . 'CoverageFunctionParenthesesTest.php',
TEST_FILES_PATH . 'CoverageFunctionParenthesesWhitespaceTest.php',
TEST_FILES_PATH . 'CoverageFunctionTest.php',
TEST_FILES_PATH . 'CoverageMethodOneLineAnnotationTest.php',
TEST_FILES_PATH . 'CoverageMethodParenthesesTest.php',
TEST_FILES_PATH . 'CoverageMethodParenthesesWhitespaceTest.php',
TEST_FILES_PATH . 'CoverageMethodTest.php',
TEST_FILES_PATH . 'CoverageNoneTest.php',
TEST_FILES_PATH . 'CoverageNotPrivateTest.php',
TEST_FILES_PATH . 'CoverageNotProtectedTest.php',
TEST_FILES_PATH . 'CoverageNotPublicTest.php',
TEST_FILES_PATH . 'CoverageNothingTest.php',
TEST_FILES_PATH . 'CoveragePrivateTest.php',
TEST_FILES_PATH . 'CoverageProtectedTest.php',
TEST_FILES_PATH . 'CoveragePublicTest.php',
TEST_FILES_PATH . 'CoverageTwoDefaultClassAnnotations.php',
TEST_FILES_PATH . 'CoveredClass.php',
TEST_FILES_PATH . 'CoveredFunction.php',
TEST_FILES_PATH . 'NamespaceCoverageClassExtendedTest.php',
TEST_FILES_PATH . 'NamespaceCoverageClassTest.php',
TEST_FILES_PATH . 'NamespaceCoverageCoversClassPublicTest.php',
TEST_FILES_PATH . 'NamespaceCoverageCoversClassTest.php',
TEST_FILES_PATH . 'NamespaceCoverageMethodTest.php',
TEST_FILES_PATH . 'NamespaceCoverageNotPrivateTest.php',
TEST_FILES_PATH . 'NamespaceCoverageNotProtectedTest.php',
TEST_FILES_PATH . 'NamespaceCoverageNotPublicTest.php',
TEST_FILES_PATH . 'NamespaceCoveragePrivateTest.php',
TEST_FILES_PATH . 'NamespaceCoverageProtectedTest.php',
TEST_FILES_PATH . 'NamespaceCoveragePublicTest.php',
TEST_FILES_PATH . 'NamespaceCoveredClass.php',
TEST_FILES_PATH . 'NotExistingCoveredElementTest.php',
TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php',
TEST_FILES_PATH . 'source_with_ignore.php',
TEST_FILES_PATH . 'source_with_namespace.php',
TEST_FILES_PATH . 'source_with_oneline_annotations.php',
TEST_FILES_PATH . 'source_without_ignore.php',
TEST_FILES_PATH . 'source_without_namespace.php'
);
}
/**
* @covers PHP_CodeCoverage_Filter::addFileToBlacklist
* @covers PHP_CodeCoverage_Filter::getBlacklist
*/
public function testAddingAFileToTheBlacklistWorks()
{
$this->filter->addFileToBlacklist($this->files[0]);
$this->assertEquals(
array($this->files[0]),
$this->filter->getBlacklist()
);
}
/**
* @covers PHP_CodeCoverage_Filter::removeFileFromBlacklist
* @covers PHP_CodeCoverage_Filter::getBlacklist
*/
public function testRemovingAFileFromTheBlacklistWorks()
{
$this->filter->addFileToBlacklist($this->files[0]);
$this->filter->removeFileFromBlacklist($this->files[0]);
$this->assertEquals(array(), $this->filter->getBlacklist());
}
/**
* @covers PHP_CodeCoverage_Filter::addDirectoryToBlacklist
* @covers PHP_CodeCoverage_Filter::getBlacklist
* @depends testAddingAFileToTheBlacklistWorks
*/
public function testAddingADirectoryToTheBlacklistWorks()
{
$this->filter->addDirectoryToBlacklist(TEST_FILES_PATH);
$blacklist = $this->filter->getBlacklist();
sort($blacklist);
$this->assertEquals($this->files, $blacklist);
}
/**
* @covers PHP_CodeCoverage_Filter::addFilesToBlacklist
* @covers PHP_CodeCoverage_Filter::getBlacklist
*/
public function testAddingFilesToTheBlacklistWorks()
{
$facade = new File_Iterator_Facade;
$files = $facade->getFilesAsArray(
TEST_FILES_PATH,
$suffixes = '.php'
);
$this->filter->addFilesToBlacklist($files);
$blacklist = $this->filter->getBlacklist();
sort($blacklist);
$this->assertEquals($this->files, $blacklist);
}
/**
* @covers PHP_CodeCoverage_Filter::removeDirectoryFromBlacklist
* @covers PHP_CodeCoverage_Filter::getBlacklist
* @depends testAddingADirectoryToTheBlacklistWorks
*/
public function testRemovingADirectoryFromTheBlacklistWorks()
{
$this->filter->addDirectoryToBlacklist(TEST_FILES_PATH);
$this->filter->removeDirectoryFromBlacklist(TEST_FILES_PATH);
$this->assertEquals(array(), $this->filter->getBlacklist());
}
/**
* @covers PHP_CodeCoverage_Filter::addFileToWhitelist
* @covers PHP_CodeCoverage_Filter::getWhitelist
*/
public function testAddingAFileToTheWhitelistWorks()
{
$this->filter->addFileToWhitelist($this->files[0]);
$this->assertEquals(
array($this->files[0]),
$this->filter->getWhitelist()
);
}
/**
* @covers PHP_CodeCoverage_Filter::removeFileFromWhitelist
* @covers PHP_CodeCoverage_Filter::getWhitelist
*/
public function testRemovingAFileFromTheWhitelistWorks()
{
$this->filter->addFileToWhitelist($this->files[0]);
$this->filter->removeFileFromWhitelist($this->files[0]);
$this->assertEquals(array(), $this->filter->getWhitelist());
}
/**
* @covers PHP_CodeCoverage_Filter::addDirectoryToWhitelist
* @covers PHP_CodeCoverage_Filter::getWhitelist
* @depends testAddingAFileToTheWhitelistWorks
*/
public function testAddingADirectoryToTheWhitelistWorks()
{
$this->filter->addDirectoryToWhitelist(TEST_FILES_PATH);
$whitelist = $this->filter->getWhitelist();
sort($whitelist);
$this->assertEquals($this->files, $whitelist);
}
/**
* @covers PHP_CodeCoverage_Filter::addFilesToWhitelist
* @covers PHP_CodeCoverage_Filter::getBlacklist
*/
public function testAddingFilesToTheWhitelistWorks()
{
$facade = new File_Iterator_Facade;
$files = $facade->getFilesAsArray(
TEST_FILES_PATH,
$suffixes = '.php'
);
$this->filter->addFilesToWhitelist($files);
$whitelist = $this->filter->getWhitelist();
sort($whitelist);
$this->assertEquals($this->files, $whitelist);
}
/**
* @covers PHP_CodeCoverage_Filter::removeDirectoryFromWhitelist
* @covers PHP_CodeCoverage_Filter::getWhitelist
* @depends testAddingADirectoryToTheWhitelistWorks
*/
public function testRemovingADirectoryFromTheWhitelistWorks()
{
$this->filter->addDirectoryToWhitelist(TEST_FILES_PATH);
$this->filter->removeDirectoryFromWhitelist(TEST_FILES_PATH);
$this->assertEquals(array(), $this->filter->getWhitelist());
}
/**
* @covers PHP_CodeCoverage_Filter::isFile
*/
public function testIsFile()
{
$this->assertFalse($this->filter->isFile('vfs://root/a/path'));
$this->assertFalse($this->filter->isFile('xdebug://debug-eval'));
$this->assertFalse($this->filter->isFile('eval()\'d code'));
$this->assertFalse($this->filter->isFile('runtime-created function'));
$this->assertFalse($this->filter->isFile('assert code'));
$this->assertFalse($this->filter->isFile('regexp code'));
$this->assertTrue($this->filter->isFile(__FILE__));
}
/**
* @covers PHP_CodeCoverage_Filter::isFiltered
*/
public function testBlacklistedFileIsFiltered()
{
$this->filter->addFileToBlacklist($this->files[0]);
$this->assertTrue($this->filter->isFiltered($this->files[0]));
}
/**
* @covers PHP_CodeCoverage_Filter::isFiltered
*/
public function testWhitelistedFileIsNotFiltered()
{
$this->filter->addFileToWhitelist($this->files[0]);
$this->assertFalse($this->filter->isFiltered($this->files[0]));
}
/**
* @covers PHP_CodeCoverage_Filter::isFiltered
*/
public function testNotWhitelistedFileIsFiltered()
{
$this->filter->addFileToWhitelist($this->files[0]);
$this->assertTrue($this->filter->isFiltered($this->files[1]));
}
/**
* @covers PHP_CodeCoverage_Filter::isFiltered
* @covers PHP_CodeCoverage_Filter::isFile
*/
public function testNonFilesAreFiltered()
{
$this->assertTrue($this->filter->isFiltered('vfs://root/a/path'));
$this->assertTrue($this->filter->isFiltered('xdebug://debug-eval'));
$this->assertTrue($this->filter->isFiltered('eval()\'d code'));
$this->assertTrue($this->filter->isFiltered('runtime-created function'));
$this->assertTrue($this->filter->isFiltered('assert code'));
$this->assertTrue($this->filter->isFiltered('regexp code'));
$this->assertFalse($this->filter->isFiltered(__FILE__));
}
}

View File

@@ -1,66 +0,0 @@
<?php
/*
* This file is part of the PHP_CodeCoverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* 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';
/**
* Tests for the PHP_CodeCoverage_Report_Clover class.
*
* @since Class available since Release 1.0.0
*/
class PHP_CodeCoverage_Report_CloverTest extends PHP_CodeCoverage_TestCase
{
/**
* @covers PHP_CodeCoverage_Report_Clover
*/
public function testCloverForBankAccountTest()
{
$clover = new PHP_CodeCoverage_Report_Clover;
$this->assertStringMatchesFormatFile(
TEST_FILES_PATH . 'BankAccount-clover.xml',
$clover->process($this->getCoverageForBankAccount(), null, 'BankAccount')
);
}
/**
* @covers PHP_CodeCoverage_Report_Clover
*/
public function testCloverForFileWithIgnoredLines()
{
$clover = new PHP_CodeCoverage_Report_Clover;
$this->assertStringMatchesFormatFile(
TEST_FILES_PATH . 'ignored-lines-clover.xml',
$clover->process($this->getCoverageForFileWithIgnoredLines())
);
}
/**
* @covers PHP_CodeCoverage_Report_Clover
*/
public function testCloverForClassWithAnonymousFunction()
{
$clover = new PHP_CodeCoverage_Report_Clover;
$this->assertStringMatchesFormatFile(
TEST_FILES_PATH . 'class-with-anonymous-function-clover.xml',
$clover->process($this->getCoverageForClassWithAnonymousFunction())
);
}
}

View File

@@ -1,222 +0,0 @@
<?php
/*
* This file is part of the PHP_CodeCoverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* 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';
/**
* Tests for the PHP_CodeCoverage_Report_Factory class.
*
* @since Class available since Release 1.1.0
*/
class PHP_CodeCoverage_Report_FactoryTest extends PHP_CodeCoverage_TestCase
{
protected $factory;
protected function setUp()
{
$this->factory = new PHP_CodeCoverage_Report_Factory;
}
public function testSomething()
{
$root = $this->getCoverageForBankAccount()->getReport();
$expectedPath = rtrim(TEST_FILES_PATH, DIRECTORY_SEPARATOR);
$this->assertEquals($expectedPath, $root->getName());
$this->assertEquals($expectedPath, $root->getPath());
$this->assertEquals(10, $root->getNumExecutableLines());
$this->assertEquals(5, $root->getNumExecutedLines());
$this->assertEquals(1, $root->getNumClasses());
$this->assertEquals(0, $root->getNumTestedClasses());
$this->assertEquals(4, $root->getNumMethods());
$this->assertEquals(3, $root->getNumTestedMethods());
$this->assertEquals('0.00%', $root->getTestedClassesPercent());
$this->assertEquals('75.00%', $root->getTestedMethodsPercent());
$this->assertEquals('50.00%', $root->getLineExecutedPercent());
$this->assertEquals(0, $root->getNumFunctions());
$this->assertEquals(0, $root->getNumTestedFunctions());
$this->assertNull($root->getParent());
$this->assertEquals(array(), $root->getDirectories());
#$this->assertEquals(array(), $root->getFiles());
#$this->assertEquals(array(), $root->getChildNodes());
$this->assertEquals(
array(
'BankAccount' => array(
'methods' => array(
'getBalance' => array(
'signature' => 'getBalance()',
'startLine' => 6,
'endLine' => 9,
'executableLines' => 1,
'executedLines' => 1,
'ccn' => 1,
'coverage' => 100,
'crap' => '1',
'link' => 'BankAccount.php.html#6',
'methodName' => 'getBalance'
),
'setBalance' => array(
'signature' => 'setBalance($balance)',
'startLine' => 11,
'endLine' => 18,
'executableLines' => 5,
'executedLines' => 0,
'ccn' => 2,
'coverage' => 0,
'crap' => 6,
'link' => 'BankAccount.php.html#11',
'methodName' => 'setBalance'
),
'depositMoney' => array(
'signature' => 'depositMoney($balance)',
'startLine' => 20,
'endLine' => 25,
'executableLines' => 2,
'executedLines' => 2,
'ccn' => 1,
'coverage' => 100,
'crap' => '1',
'link' => 'BankAccount.php.html#20',
'methodName' => 'depositMoney'
),
'withdrawMoney' => array(
'signature' => 'withdrawMoney($balance)',
'startLine' => 27,
'endLine' => 32,
'executableLines' => 2,
'executedLines' => 2,
'ccn' => 1,
'coverage' => 100,
'crap' => '1',
'link' => 'BankAccount.php.html#27',
'methodName' => 'withdrawMoney'
),
),
'startLine' => 2,
'executableLines' => 10,
'executedLines' => 5,
'ccn' => 5,
'coverage' => 50,
'crap' => '8.12',
'package' => array(
'namespace' => '',
'fullPackage' => '',
'category' => '',
'package' => '',
'subpackage' => ''
),
'link' => 'BankAccount.php.html#2',
'className' => 'BankAccount'
)
),
$root->getClasses()
);
$this->assertEquals(array(), $root->getFunctions());
}
/**
* @covers PHP_CodeCoverage_Report_Factory::buildDirectoryStructure
*/
public function testBuildDirectoryStructure()
{
$method = new ReflectionMethod(
'PHP_CodeCoverage_Report_Factory',
'buildDirectoryStructure'
);
$method->setAccessible(true);
$this->assertEquals(
array(
'src' => array(
'Money.php/f' => array(),
'MoneyBag.php/f' => array()
)
),
$method->invoke(
$this->factory,
array('src/Money.php' => array(), 'src/MoneyBag.php' => array())
)
);
}
/**
* @covers PHP_CodeCoverage_Report_Factory::reducePaths
* @dataProvider reducePathsProvider
*/
public function testReducePaths($reducedPaths, $commonPath, $paths)
{
$method = new ReflectionMethod(
'PHP_CodeCoverage_Report_Factory',
'reducePaths'
);
$method->setAccessible(true);
$_commonPath = $method->invokeArgs($this->factory, array(&$paths));
$this->assertEquals($reducedPaths, $paths);
$this->assertEquals($commonPath, $_commonPath);
}
public function reducePathsProvider()
{
return array(
array(
array(
'Money.php' => array(),
'MoneyBag.php' => array()
),
'/home/sb/Money',
array(
'/home/sb/Money/Money.php' => array(),
'/home/sb/Money/MoneyBag.php' => array()
)
),
array(
array(
'Money.php' => array()
),
'/home/sb/Money/',
array(
'/home/sb/Money/Money.php' => array()
)
),
array(
array(),
'.',
array()
),
array(
array(
'Money.php' => array(),
'MoneyBag.php' => array(),
'Cash.phar/Cash.php' => array(),
),
'/home/sb/Money',
array(
'/home/sb/Money/Money.php' => array(),
'/home/sb/Money/MoneyBag.php' => array(),
'phar:///home/sb/Money/Cash.phar/Cash.php' => array(),
),
),
);
}
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of the PHP_CodeCoverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Tests for the PHP_CodeCoverage_Util class.
*
* @since Class available since Release 1.0.0
*/
class PHP_CodeCoverage_UtilTest extends PHPUnit_Framework_TestCase
{
/**
* @covers PHP_CodeCoverage_Util::percent
*/
public function testPercent()
{
$this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 0));
$this->assertEquals(100, PHP_CodeCoverage_Util::percent(100, 100));
$this->assertEquals(
'100.00%',
PHP_CodeCoverage_Util::percent(100, 100, true)
);
}
}

View File

@@ -1,487 +0,0 @@
<?php
/*
* This file is part of the PHP_CodeCoverage package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* 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';
/**
* Tests for the PHP_CodeCoverage class.
*
* @since Class available since Release 1.0.0
*/
class PHP_CodeCoverageTest extends PHP_CodeCoverage_TestCase
{
/**
* @var PHP_CodeCoverage
*/
private $coverage;
protected function setUp()
{
$this->coverage = new PHP_CodeCoverage;
}
/**
* @covers PHP_CodeCoverage::__construct
* @covers PHP_CodeCoverage::filter
*/
public function testConstructor()
{
$this->assertAttributeInstanceOf(
'PHP_CodeCoverage_Driver_Xdebug',
'driver',
$this->coverage
);
$this->assertAttributeInstanceOf(
'PHP_CodeCoverage_Filter',
'filter',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::__construct
* @covers PHP_CodeCoverage::filter
*/
public function testConstructor2()
{
$filter = new PHP_CodeCoverage_Filter;
$coverage = new PHP_CodeCoverage(null, $filter);
$this->assertAttributeInstanceOf(
'PHP_CodeCoverage_Driver_Xdebug',
'driver',
$coverage
);
$this->assertSame($filter, $coverage->filter());
}
/**
* @covers PHP_CodeCoverage::start
* @expectedException PHP_CodeCoverage_Exception
*/
public function testStartThrowsExceptionForInvalidArgument()
{
$this->coverage->start(null, array(), null);
}
/**
* @covers PHP_CodeCoverage::stop
* @expectedException PHP_CodeCoverage_Exception
*/
public function testStopThrowsExceptionForInvalidArgument()
{
$this->coverage->stop(null);
}
/**
* @covers PHP_CodeCoverage::stop
* @expectedException PHP_CodeCoverage_Exception
*/
public function testStopThrowsExceptionForInvalidArgument2()
{
$this->coverage->stop(true, null);
}
/**
* @covers PHP_CodeCoverage::append
* @expectedException PHP_CodeCoverage_Exception
*/
public function testAppendThrowsExceptionForInvalidArgument()
{
$this->coverage->append(array(), null);
}
/**
* @covers PHP_CodeCoverage::setCacheTokens
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetCacheTokensThrowsExceptionForInvalidArgument()
{
$this->coverage->setCacheTokens(null);
}
/**
* @covers PHP_CodeCoverage::setCacheTokens
*/
public function testSetCacheTokens()
{
$this->coverage->setCacheTokens(true);
$this->assertAttributeEquals(true, 'cacheTokens', $this->coverage);
}
/**
* @covers PHP_CodeCoverage::setCheckForUnintentionallyCoveredCode
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetCheckForUnintentionallyCoveredCodeThrowsExceptionForInvalidArgument()
{
$this->coverage->setCheckForUnintentionallyCoveredCode(null);
}
/**
* @covers PHP_CodeCoverage::setCheckForUnintentionallyCoveredCode
*/
public function testSetCheckForUnintentionallyCoveredCode()
{
$this->coverage->setCheckForUnintentionallyCoveredCode(true);
$this->assertAttributeEquals(
true,
'checkForUnintentionallyCoveredCode',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setForceCoversAnnotation
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetForceCoversAnnotationThrowsExceptionForInvalidArgument()
{
$this->coverage->setForceCoversAnnotation(null);
}
/**
* @covers PHP_CodeCoverage::setForceCoversAnnotation
*/
public function testSetForceCoversAnnotation()
{
$this->coverage->setForceCoversAnnotation(true);
$this->assertAttributeEquals(
true,
'forceCoversAnnotation',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setAddUncoveredFilesFromWhitelist
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetAddUncoveredFilesFromWhitelistThrowsExceptionForInvalidArgument()
{
$this->coverage->setAddUncoveredFilesFromWhitelist(null);
}
/**
* @covers PHP_CodeCoverage::setAddUncoveredFilesFromWhitelist
*/
public function testSetAddUncoveredFilesFromWhitelist()
{
$this->coverage->setAddUncoveredFilesFromWhitelist(true);
$this->assertAttributeEquals(
true,
'addUncoveredFilesFromWhitelist',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setProcessUncoveredFilesFromWhitelist
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetProcessUncoveredFilesFromWhitelistThrowsExceptionForInvalidArgument()
{
$this->coverage->setProcessUncoveredFilesFromWhitelist(null);
}
/**
* @covers PHP_CodeCoverage::setProcessUncoveredFilesFromWhitelist
*/
public function testSetProcessUncoveredFilesFromWhitelist()
{
$this->coverage->setProcessUncoveredFilesFromWhitelist(true);
$this->assertAttributeEquals(
true,
'processUncoveredFilesFromWhitelist',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setMapTestClassNameToCoveredClassName
*/
public function testSetMapTestClassNameToCoveredClassName()
{
$this->coverage->setMapTestClassNameToCoveredClassName(true);
$this->assertAttributeEquals(
true,
'mapTestClassNameToCoveredClassName',
$this->coverage
);
}
/**
* @covers PHP_CodeCoverage::setMapTestClassNameToCoveredClassName
* @expectedException PHP_CodeCoverage_Exception
*/
public function testSetMapTestClassNameToCoveredClassNameThrowsExceptionForInvalidArgument()
{
$this->coverage->setMapTestClassNameToCoveredClassName(null);
}
/**
* @covers PHP_CodeCoverage::clear
*/
public function testClear()
{
$this->coverage->clear();
$this->assertAttributeEquals(null, 'currentId', $this->coverage);
$this->assertAttributeEquals(array(), 'data', $this->coverage);
$this->assertAttributeEquals(array(), 'tests', $this->coverage);
}
/**
* @covers PHP_CodeCoverage::start
* @covers PHP_CodeCoverage::stop
* @covers PHP_CodeCoverage::append
* @covers PHP_CodeCoverage::applyListsFilter
* @covers PHP_CodeCoverage::initializeFilesThatAreSeenTheFirstTime
* @covers PHP_CodeCoverage::applyCoversAnnotationFilter
* @covers PHP_CodeCoverage::getTests
*/
public function testCollect()
{
$coverage = $this->getCoverageForBankAccount();
$this->assertEquals(
$this->getExpectedDataArrayForBankAccount(),
$coverage->getData()
);
if (version_compare(PHPUnit_Runner_Version::id(), '4.7', '>=')) {
$size = 'unknown';
} else {
$size = 'small';
}
$this->assertEquals(
array(
'BankAccountTest::testBalanceIsInitiallyZero' => array('size' => $size, 'status' => null),
'BankAccountTest::testBalanceCannotBecomeNegative' => array('size' => $size, 'status' => null),
'BankAccountTest::testBalanceCannotBecomeNegative2' => array('size' => $size, 'status' => null),
'BankAccountTest::testDepositWithdrawMoney' => array('size' => $size, 'status' => null)
),
$coverage->getTests()
);
}
/**
* @covers PHP_CodeCoverage::getData
* @covers PHP_CodeCoverage::merge
*/
public function testMerge()
{
$coverage = $this->getCoverageForBankAccountForFirstTwoTests();
$coverage->merge($this->getCoverageForBankAccountForLastTwoTests());
$this->assertEquals(
$this->getExpectedDataArrayForBankAccount(),
$coverage->getData()
);
}
/**
* @covers PHP_CodeCoverage::getData
* @covers PHP_CodeCoverage::merge
*/
public function testMerge2()
{
$coverage = new PHP_CodeCoverage(
$this->getMock('PHP_CodeCoverage_Driver_Xdebug'),
new PHP_CodeCoverage_Filter
);
$coverage->merge($this->getCoverageForBankAccount());
$this->assertEquals(
$this->getExpectedDataArrayForBankAccount(),
$coverage->getData()
);
}
/**
* @covers PHP_CodeCoverage::getLinesToBeIgnored
*/
public function testGetLinesToBeIgnored()
{
$this->assertEquals(
array(
1,
3,
4,
5,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
30,
32,
33,
34,
35,
36,
37,
38
),
$this->getLinesToBeIgnored()->invoke(
$this->coverage,
TEST_FILES_PATH . 'source_with_ignore.php'
)
);
}
/**
* @covers PHP_CodeCoverage::getLinesToBeIgnored
*/
public function testGetLinesToBeIgnored2()
{
$this->assertEquals(
array(1, 5),
$this->getLinesToBeIgnored()->invoke(
$this->coverage,
TEST_FILES_PATH . 'source_without_ignore.php'
)
);
}
/**
* @covers PHP_CodeCoverage::getLinesToBeIgnored
*/
public function testGetLinesToBeIgnored3()
{
$this->assertEquals(
array(
1,
2,
3,
4,
5,
8,
11,
15,
16,
19,
20
),
$this->getLinesToBeIgnored()->invoke(
$this->coverage,
TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php'
)
);
}
/**
* @covers PHP_CodeCoverage::getLinesToBeIgnored
*/
public function testGetLinesToBeIgnoredOneLineAnnotations()
{
$this->assertEquals(
array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
18,
20,
21,
23,
24,
25,
27,
28,
29,
30,
31,
32,
33,
34,
37
),
$this->getLinesToBeIgnored()->invoke(
$this->coverage,
TEST_FILES_PATH . 'source_with_oneline_annotations.php'
)
);
}
/**
* @return ReflectionMethod
*/
private function getLinesToBeIgnored()
{
$getLinesToBeIgnored = new ReflectionMethod(
'PHP_CodeCoverage',
'getLinesToBeIgnored'
);
$getLinesToBeIgnored->setAccessible(true);
return $getLinesToBeIgnored;
}
/**
* @covers PHP_CodeCoverage::getLinesToBeIgnored
*/
public function testGetLinesToBeIgnoredWhenIgnoreIsDisabled()
{
$this->coverage->setDisableIgnoredLines(true);
$this->assertEquals(
array(),
$this->getLinesToBeIgnored()->invoke(
$this->coverage,
TEST_FILES_PATH . 'source_with_ignore.php'
)
);
}
}