Skip to content

Commit

Permalink
Automatic registration of CollectTestExecutionMemoryFootprints
Browse files Browse the repository at this point in the history
This patch allows for `CollectTestExecutionMemoryFootprints` to be automatically
registered when running `vendor/bin/roave-no-leaks`: this means that the
`phpunit.xml` changes are no longer required for end users
  • Loading branch information
Ocramius committed Mar 21, 2019
1 parent fc47e28 commit 66aadb1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 74 deletions.
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ composer require --dev roave/no-leaks

## Usage

In your `phpunit.xml` configuration, add following section:

```xml
<listeners>
<listener class="Roave\NoLeaks\PHPUnit\CollectTestExecutionMemoryFootprints"/>
</listeners>

<extensions>
<extension class="Roave\NoLeaks\PHPUnit\CollectTestExecutionMemoryFootprints"/>
</extensions>
```

Then run:

```sh
vendor/bin/roave-no-leaks
```
Expand Down
34 changes: 31 additions & 3 deletions bin/roave-no-leaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Roave\NoLeaks\CLI;

use Roave\NoLeaks\PHPUnit\PHPUnitCommand;
use PHPUnit\TextUI\Command;
use PHPUnit\TextUI\TestRunner;
use Roave\NoLeaks\PHPUnit\CollectTestExecutionMemoryFootprints;

(function () {
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
Expand All @@ -13,7 +15,33 @@
require_once __DIR__ . '/../../../autoload.php';
}

$_SERVER['argv'][] = '--repeat=3';
(new class extends Command
{
/** @var CollectTestExecutionMemoryFootprints */
private $collector;

PHPUnitCommand::main();
public function __construct()
{
$this->collector = new CollectTestExecutionMemoryFootprints();
}

protected function handleArguments(array $argv) : void
{
parent::handleArguments($argv);

$this->arguments['listeners'] = array_merge(
$this->arguments['listeners'] ?? [],
[$this->collector]
);
}

protected function createRunner() : TestRunner
{
$runner = parent::createRunner();

$runner->addExtension($this->collector);

return $runner;
}
})->run(array_merge($_SERVER['argv'], ['--repeat=3']), true);
})();
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
verbose="true"
executionOrder="random"
>
<php>
<!-- to autoconfigure roave/no-leaks -->
<env name="REGISTER_NO_LEAKS" value="false" />
</php>

<testsuites>
<testsuite name="unit">
<directory>./test/unit</directory>
Expand Down
44 changes: 0 additions & 44 deletions src/PHPUnitCommand.php

This file was deleted.

8 changes: 0 additions & 8 deletions test/e2e/phpunit-mock-suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
beStrictAboutTodoAnnotatedTests="true"
verbose="true"
>
<listeners>
<listener class="Roave\NoLeaks\PHPUnit\CollectTestExecutionMemoryFootprints"/>
</listeners>

<extensions>
<extension class="Roave\NoLeaks\PHPUnit\CollectTestExecutionMemoryFootprints"/>
</extensions>

<testsuites>
<testsuite name="Memleak detection e2e tests">
<file>./LeakyIntegrationTest.php</file>
Expand Down

0 comments on commit 66aadb1

Please sign in to comment.