Note
This project is no longer maintained. Use the official Pest Rector rules instead.
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.
You can install the package via composer.
composer require worksome/pretty-pest --devYou 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:
EnsureTestFunctionsAreOrderedNewLineAfterTestFunctions
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>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.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.