-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from JanTvrdik/pr/manual_code_coverage_save
Allow manually save partial code coverage to free memory
- Loading branch information
Showing
3 changed files
with
83 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Tester\Assert; | ||
use Tester\CodeCoverage; | ||
use Tester\FileMock; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
if (!extension_loaded('xdebug') && (!defined('PHPDBG_VERSION') || PHP_VERSION_ID < 70000)) { | ||
Tester\Environment::skip('Requires Xdebug or phpdbg SAPI.'); | ||
} | ||
|
||
if (CodeCoverage\Collector::isStarted()) { | ||
Tester\Environment::skip('Requires running without --coverage.'); | ||
} | ||
|
||
$outputFile = FileMock::create(''); | ||
|
||
Assert::false(CodeCoverage\Collector::isStarted()); | ||
CodeCoverage\Collector::start($outputFile); | ||
Assert::true(CodeCoverage\Collector::isStarted()); | ||
|
||
Assert::exception(function () use ($outputFile) { | ||
CodeCoverage\Collector::start($outputFile); | ||
}, 'LogicException', 'Code coverage collector has been already started.'); | ||
|
||
$content = file_get_contents($outputFile); | ||
Assert::same('', $content); | ||
|
||
CodeCoverage\Collector::save(); | ||
$coverage = unserialize(file_get_contents($outputFile)); | ||
Assert::type('array', $coverage); | ||
Assert::same(1, $coverage[__FILE__][__LINE__ - 3]); // line with 1st Collector::save() | ||
|
||
CodeCoverage\Collector::save(); // save() can be called repeatedly | ||
$coverage = unserialize(file_get_contents($outputFile)); | ||
Assert::type('array', $coverage); | ||
Assert::same(1, $coverage[__FILE__][__LINE__ - 8]); // line with 1st Collector::save() | ||
Assert::same(1, $coverage[__FILE__][__LINE__ - 4]); // line with 2nd Collector::save() |
This file was deleted.
Oops, something went wrong.