Skip to content

Commit

Permalink
Merge pull request #11 from Roave/feature/#8-automatic-extension-regi…
Browse files Browse the repository at this point in the history
…stration

#8 Automatic registration of `CollectTestExecutionMemoryFootprints`
  • Loading branch information
Ocramius authored Mar 21, 2019
2 parents 0b25ae1 + 66aadb1 commit 585fece
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 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
32 changes: 30 additions & 2 deletions bin/roave-no-leaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Roave\NoLeaks\CLI;

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;

Command::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);
})();
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 585fece

Please sign in to comment.