Работает ли покрытие кода PHPUnit_Selenium?
В документах PHPUnitон говорит, что возможно получить данные покрытия кода:
PHPUnit_Extensions_SeleniumTestCase can collect code coverage information for tests run through Selenium:
Copy PHPUnit/Extensions/SeleniumTestCase/phpunit_coverage.php into your webserver's document root directory.
In your webserver's php.ini configuration file, configure PHPUnit/Extensions/SeleniumTestCase/prepend.php and PHPUnit/Extensions/SeleniumTestCase/append.php as the auto_prepend_file and auto_append_file, respectively.
In your test case class that extends PHPUnit_Extensions_SeleniumTestCase, use protected $coverageScriptUrl = 'http://host/phpunit_coverage.php'; to configure the URL for the phpunit_coverage.php script.
Я не смог получить эту информацию для вывода какой-либо информации о покрытии. Я могу получить информацию о покрытии кода с помощью обычных модульных тестов.
Для моего приложения работает наhttp://localhost/ts2_templates/
Я скопировалphpunit_coverage.php
вhttp://localhost/phpunit_coverage.php
.
Я добавил следующее в php.ini:
auto_prepend_file = "/path/to/pear/share/pear/PHPUnit/Extensions/SeleniumTestCase/prepend.php"
auto_append_file = "/path/to/pear/share/pear/PHPUnit/Extensions/SeleniumTestCase/append.php"
... и подтвердил, что им звонят сdie("yep it's me");
.
Наконец, я добавил следующее в свой тестовый пример:
<?php
class WebTest extends PHPUnit_Extensions_Selenium2TestCase
{
# added line below
protected $coverageScriptUrl = 'http://localhost/phpunit_coverage.php';
protected function setUp()
{
$this->setBrowser('firefox');
$this->setBrowserUrl('http://localhost/ts2_templates');
}
public function testTitle()
{
$this->url('http://localhost/ts2_templates');
$this->assertContains('test', $this->title());
}
}
?>
Вот команда для запуска теста с покрытием кода, сгенерированного PHPStorm:
/Applications/MAMP/bin/php5.3/bin/php -dxdebug.coverage_enable=1 /private/var/folders/pp/0t4y41f95j5313qm_f8b42fw0000gn/T/ide-phpunit.php --coverage-clover /path/to/coverage/ts2_templates$WebTest.coverage --no-configuration WebTest /Users/Ian/php/ts2_templates/tests/WebTest.php
Вот вывод XML-файла покрытия:
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1341015508">
<project timestamp="1341015508">
<metrics files="0" loc="0" ncloc="0" classes="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
</project>
</coverage>
Сам тест проходит.
Я подтвердил, что в коде нет ни одного оператора завершения или выхода.
Есть идеи?