Download the PHP package forknetwork/strict-phpunit without Composer
On this page you can find all versions of the php package forknetwork/strict-phpunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download forknetwork/strict-phpunit
More information about forknetwork/strict-phpunit
Files in forknetwork/strict-phpunit
Package strict-phpunit
Short Description A simple PHPUnit extension that disallows unexpected method calls.
License Apache-2.0
Informations about the package strict-phpunit
StrictPHPUnit
A simple PHPUnit extension that disallows unexpected method calls.
For PHPUnit 7.1 and up.
Installation
How to use
The StrictTestTrait
can be used by any class that extends from TestCase
of PHPUnit. This trait can be added automatically using the PHP Code Sniffer.
Before
After
Overwrite strict mock generation
By default all mocks will be strict, but in some cases that won't work. For example, PHPUnit doesn't handle the destruct method for mocks well. In those cases you might want to enable the value generation again.
Before
After
Another option would to remove the trait from the class and manually add ->disableAutoReturnValueGeneration()
onto the mocks your want strict.
Optional: PHP code sniffer and fixer
This library comes with a code sniff with auto-fixer. Just include the reference in your phpcs.xml(.dist)
file and run the code sniffer as usual.
By default it will sniff all classes that extend from TestCase
(PHPUnit). You can change which extended class it should sniff by adding this to your configuration.
Please note that this sniff only ensures the trait and use statements are added. It does not sort or pay attention to the rest of your code style.
Known limitations
The current implementation of the sniff doesn't support the following situations:
- Comma separated use trait statements (e.g.
use StrictUnitTrait, FooTrait;
) - FQCN or partial use trait statements (e.g.
use Traits\StrictUnitTest;
) - Running the sniff unit tests in PHPUnit 8 or higher is not supported.