Skip to content

Instantly share code, notes, and snippets.

@edorian
Created September 6, 2012 11:04
Show Gist options
  • Save edorian/3654855 to your computer and use it in GitHub Desktop.
Save edorian/3654855 to your computer and use it in GitHub Desktop.
PHPUnit memory test listener
phpunit.xml.dist:
<listeners>
<listener class="MemoryTestListener" file="./MemoryTestListener.php">
</listeners>
In the same folder: MemoryTestListener.php
<?php
class MemoryTestListener implements PHPUnit_Framework_TestListener
{
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function startTest(PHPUnit_Framework_Test $test) {}
public function endTest(PHPUnit_Framework_Test $test, $time)
{
var_dump(round(memory_get_peak_usage() / 1024 / 1024));
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment