jclaveau / phpunit-profile-asserts
Provides asserts against memory usage and execution time for PHPUnit
Installs: 1 506
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: >=5.6
- phpunit/phpunit: 5.*
- symfony/stopwatch: ^3.4
This package is auto-updated.
Last update: 2024-11-06 10:18:11 UTC
README
This lib provides asserts against execution time and memory usage. It also provides a StopwatchListener based on the Stopwatch component of Symfony.
Installation
phpunit-profile-asserts is installable via Composer
and should be added as a require-dev
dependency:
composer require --dev jclaveau/phpunit-profile-asserts
Usage
Enable by adding the following code to your project's phpunit.xml
file:
<phpunit bootstrap="vendor/autoload.php"> ... <listeners> <listener class="JClaveau\PHPUnit\Listener\StopwatchListener" /> </listeners> </phpunit>
class SomeTestCase extends \PHPUnit_Framework_TestCase { use \JClaveau\PHPUnit\Framework\UsageConstraintTrait; // adds the asserts methods /** */ public function test_usages() { // ... $this->assertExecutionTimeBelow(1.5); // seconds $this->assertMemoryUsageBelow('1M'); // This trait also provides two methods to help knowing the current // memory usage and duration $this->getMemoryUsage(); $this->getExecutionTime(); } }
TODO
- PHP 7 implementation (find an elegant way to support PHP 5 and 7 together)
- Integrate SpeedTrap and adds MemoryTrap
- Investigate xhprof integration and asserts on number of calls / execution time of specific methods/functions
Inspiration
- https://github.com/usernam3/phpunit_stopwatch_annotations
- https://github.com/johnkary/phpunit-speedtrap
License
phpunit-profile-asserts is available under the MIT License.