8000 [PhpUnitBridge] Added a CoverageListener to enhance the code coverage report by lyrixx · Pull Request #23149 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Added a CoverageListener to enhance the code coverage report #23149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
Added test for the CoverageListener
  • Loading branch information
lyrixx committed Sep 21, 2017
commit 30381f4e8530f595ba4be06c19721ca9f7c5e596
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>

<testsuites>
<testsuite name="Fixtures/coverage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\CoverageListener" />
</listeners>
</phpunit>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
failOnRisky="true"
failOnWarning="true"
>

<testsuites>
<testsuite name="Fixtures/coverage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
27 changes: 27 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Tests-Fixtures/coverage/src/Bar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

class Bar
{
private $foo;

public function __construct(Foo $foo)
{
$this->foo = $foo;
}

public function barZ()
{
$this->foo->fooZ();

return 'bar';
}
}
18 changes: 18 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Tests-Fixtures/coverage/src/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

class Foo
{
public function fooZ()
{
return 'foo';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

class BarTest extends TestCase
{
public function testBar()
{
$foo = new Foo();
$bar = new Bar($foo);

$this->assertSame('bar', $bar->barZ());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require __DIR__.'/../src/Bar.php';
require __DIR__.'/../src/Foo.php';

require __DIR__.'/../../../Legacy/CoverageListenerTrait.php';
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
require __DIR__.'/../../../Legacy/CoverageListener.php';
}
require __DIR__.'/../../../CoverageListener.php';
27 changes: 27 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Symfony\Bridge\PhpUnit\Tests;

use PHPUnit\Framework\TestCase;

class CoverageListenerTest extends TestCase
{
public function test()
{
if ("\n" !== PHP_EOL) {
$this->markTestSkipped('This test cannot be run on Windows.');
}

$dir = __DIR__.'/../Tests-Fixtures/coverage';
$php = PHP_BINARY;
$phpunit = $_SERVER['argv'][0];

exec("$php -d zend_extension=xdebug.so $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text", $output);
$output = implode("\n", $output);
$this->assertNotContains('Foo', $output);

exec("$php -d zend_extension=xdebug.so $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text", $output);
$output = implode("\n", $output);
$this->assertContains('Foo', $output);
}
}
0