worksome / pretty-pest
Automatically format your Pest PHP tests.
Installs: 359 824
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 15
Forks: 1
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: ^8.2
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- squizlabs/php_codesniffer: ^3.8.1
Requires (Dev)
- pestphp/pest: ^2.33
README
Enforce consistent styling for your Pest PHP tests!
There are lots of important decisions to worry about as a developer. You know what you shouldn't be worrying about? The order of your tests! But you still want your tests to look nice, right?
That's why we created Pretty Pest. This code style plugin ensures that your Pest tests are automatically formatted correctly so that you don't have to spend time doing so manually.
Installation
You can install the package via composer.
composer require worksome/pretty-pest --dev
PHPCBF
You can enable Pretty Pest in PHPCBF by adding the PrettyPest
rule to your phpcs.xml
file.
<rule ref="PrettyPest"/>
Pretty Pest has 2 sniffs for PHPCBF:
EnsureTestFunctionsAreOrdered
NewLineAfterTestFunctions
EnsureTestFunctionsAreOrdered
This sniff will ensure that your pest functions are ordered correctly in the test file. By default, we use the following order:
[ 'uses', 'beforeAll', 'beforeEach', 'afterEach', 'afterAll', // The array syntax indicates that `test` and `it` are to be treated as the same function. ['test', 'it'], 'dataset', ]
Any functions that are out of order will be moved in the file. Of course, you can always override this order to your preference in the phpcs.xml
file.
<rule ref="PrettyPest.Formatting.EnsureFunctionsAreOrdered"> <properties> <property name="order" type="array"> <element value="uses"/> <element value="beforeAll"/> <element value="beforeEach"/> <element value="test"/> <element value="it"/> <element value="dataset"/> <element value="afterEach"/> <element value="afterAll"/> </property> </properties> </rule>
NewLineAfterTestFunctions
This sniff will replace all whitespace after a Pest function with a single new line to ensure that spacing in your test files is consistent.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.