loophp / phpspec-time
A PHPSpec extension providing matchers for measuring time in tests.
Fund package maintenance!
drupol
www.paypal.me/drupol
Requires
- php: >= 7.4
- loophp/nanobench: ^1
Requires (Dev)
- drupol/php-conventions: ^3.0.2
- friends-of-phpspec/phpspec-code-coverage: ^5
- infection/infection: ^0.21
- infection/phpspec-adapter: ^0.1.2
- phpspec/phpspec: ^7
- phpstan/phpstan-strict-rules: ^0.12
- vimeo/psalm: ^4
This package is auto-updated.
Last update: 2022-03-21 10:52:37 UTC
README
PHPSpec Time
A PHPSpec extension providing matchers for measuring time in tests.
New matchers:
shouldTakeLessThan(float $timeUnit)
shouldTakeMoreThan(float $timeUnit)
shouldTakeInBetween(float $fromTimeUnit, float $toTimeUnit)
Installation
composer require loophp/phpspec-time
Usage
Add the extension to the phpspec configuration file:
extensions: loophp\phpspectime\Extension: ~
By default, the time unit is in second
, however other units are available:
nanosecond
microsecond
millisecond
second
minute
hour
day
week
If you want to change the time unit edit the extension configuration as such:
extensions: loophp\phpspectime\Extension: timeunit: nanosecond
In your tests, you'll have now access to the following new matchers:
$this ->shouldTakeMoreThan(10) ->during('method'); $this ->shouldNotTakeMoreThan(10) ->during('method'); $this ->shouldTakeLessThan(10) ->during('method'); $this ->shouldNotTakeLessThan(10) ->during('method'); $this ->shouldTakeInBetween(3.0, 3.2) ->during('method'); $this ->shouldNotTakeInBetween(3.0, 3.2) ->during('method');
Code quality, tests and benchmarks
Every time changes are introduced into the library, Github run the tests.
The library has tests written with PHPSpec.
Feel free to check them out in the spec
directory. Run composer phpspec
to trigger the tests.
Before each commit some inspections are executed with GrumPHP,
run composer grumphp
to check manually.
The quality of the tests is tested with Infection a PHP Mutation testing
framework, run composer infection
to try it.
Static analysers are also controlling the code. PHPStan and PSalm are enabled to their maximum level.
Contributing
Feel free to contribute by sending Github pull requests. I'm quite reactive :-)
If you can't contribute to the code, you can also sponsor me on Github or Paypal.
Changelog
See CHANGELOG.md for a changelog based on git commits.
For more detailed changelogs, please check the release changelogs.