Skip to content

Commit

Permalink
bug #26089 [PhpUnitBridge] Added support for PHPUnit 7 in Coverage Li…
Browse files Browse the repository at this point in the history
…stener (lyrixx)

This PR was merged into the 3.4 branch.

Discussion
----------

[PhpUnitBridge] Added support for PHPUnit 7 in Coverage Listener

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

6c0e6af [PhpUnitBridge] Added support for PHPUnit 7 in Coverage Listener
  • Loading branch information
nicolas-grekas committed Feb 14, 2018
2 parents 0f4704d + 6c0e6af commit b4cdb19
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 31 deletions.
32 changes: 4 additions & 28 deletions src/Symfony/Bridge/PhpUnit/CoverageListener.php
Expand Up @@ -11,34 +11,10 @@

namespace Symfony\Bridge\PhpUnit;

use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;
use Symfony\Bridge\PhpUnit\Legacy\CoverageListenerTrait;

if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListener', 'Symfony\Bridge\PhpUnit\CoverageListener');
// Using an early return instead of a else does not work when using the PHPUnit
// phar due to some weird PHP behavior (the class gets defined without executing
// the code before it and so the definition is not properly conditional)
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV5', 'Symfony\Bridge\PhpUnit\CoverageListener');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV6', 'Symfony\Bridge\PhpUnit\CoverageListener');
} else {
/**
* CoverageListener adds `@covers <className>` on each test suite when possible
* to make the code coverage more accurate.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class CoverageListener extends BaseTestListener
{
private $trait;

public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
{
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
}

public function startTest(Test $test)
{
$this->trait->startTest($test);
}
}
class_alias('Symfony\Bridge\PhpUnit\Legacy\CoverageListenerForV7', 'Symfony\Bridge\PhpUnit\CoverageListener');
}
Expand Up @@ -19,7 +19,7 @@
*
* @internal
*/
class CoverageListener extends \PHPUnit_Framework_BaseTestListener
class CoverageListenerForV5 extends \PHPUnit_Framework_BaseTestListener
{
private $trait;

Expand Down
38 changes: 38 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerForV6.php
@@ -0,0 +1,38 @@
<?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.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\BaseTestListener;
use PHPUnit\Framework\Test;

/**
* CoverageListener adds `@covers <className>` on each test suite when possible
* to make the code coverage more accurate.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @internal
*/
class CoverageListenerForV6 extends BaseTestListener
{
private $trait;

public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
{
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
}

public function startTest(Test $test)
{
$this->trait->startTest($test);
}
}
41 changes: 41 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/CoverageListenerForV7.php
@@ -0,0 +1,41 @@
<?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.
*/

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;

/**
* CoverageListener adds `@covers <className>` on each test suite when possible
* to make the code coverage more accurate.
*
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*
* @internal
*/
class CoverageListenerForV7 implements TestListener
{
use TestListenerDefaultImplementation;

private $trait;

public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
{
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
}

public function startTestSuite(TestSuite $suite): void
{
$this->trait->startTest($test);
}
}
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Expand Up @@ -16,7 +16,9 @@ public function test()
$this->markTestSkipped('This test cannot be run on HHVM.');
}

if (\PHP_VERSION_ID >= 70000) {
exec('type phpdbg', $output, $returnCode);

if (\PHP_VERSION_ID >= 70000 && 0 === $returnCode) {
$php = 'phpdbg -qrr';
} else {
exec('php --ri xdebug -d zend_extension=xdebug.so 2> /dev/null', $output, $returnCode);
Expand Down
Expand Up @@ -13,7 +13,13 @@
require __DIR__.'/../src/FooCov.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_once __DIR__.'/../../../../Legacy/CoverageListenerForV5.php';
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '<')) {
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV6.php';
} else {
require_once __DIR__.'/../../../../Legacy/CoverageListenerForV7.php';
}

require __DIR__.'/../../../../CoverageListener.php';

0 comments on commit b4cdb19

Please sign in to comment.