Я пишу контрольные примеры с PHPUnit 8
, но я сталкиваюсь с проблемой, заключающейся в том, что функциональность покрытия кода PHPUnit 8
не работает для статических методов класса.
Моя среда находится под Windows 7с использованием следующих компонентов:
- Версия Composer 1.8.0 2018-12-03 10: 31: 16
- PHPUnit 8
- PHP CLI 7.2.4 сXdebug v2.6.0
Вот несколько кодов, которые я написал.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
class UtilsTest extends TestCase {
/**
* @return DateTime
*/
public function testAddDays() {
$dateTime = new DateTime('2019-04-02');
$actualDateTime = Utils::addDays($dateTime, 8);
$this->assertSame('2019-04-10', $actualDateTime->format('Y-m-d'));
return $actualDateTime;
}
/**
* @param DateTime
* @depends testAddDays
*/
public function testAddHours(DateTime $dateTime) {
$actualDateTime = Utils::addHours($dateTime, 8);
$this->assertSame('2019-04-10 08', $actualDateTime->format('Y-m-d H'));
}
public function testIsWhichDayInWeek() {
$dt0 = new DateTime('2019-04-08');
$dt1 = new DateTime('2019-04-09');
$dt2 = new DateTime('2019-04-10');
$dt3 = new DateTime('2019-04-11');
$dt4 = new DateTime('2019-04-12');
$dt5 = new DateTime('2019-04-13');
$dt6 = new DateTime('2019-04-14');
$this->assertSame(true, Utils::isMonday($dt0));
$this->assertSame(true, Utils::isTuesday($dt1));
$this->assertSame(true, Utils::isWednesday($dt2));
$this->assertSame(true, Utils::isThursday($dt3));
$this->assertSame(true, Utils::isFriday($dt4));
$this->assertSame(true, Utils::isSaturday($dt5));
$this->assertSame(true, Utils::isSunday($dt6));
}
}
Не удалось рассчитать степень покрытия кода при запуске команды .\vendor\bin\phpunit tests\UtilsTest.php --coverage-html ./build
