@@ -8,17 +8,8 @@ SPDX-License-Identifier: MIT
88Contributions to Respect\Validation are always welcome. You make our lives
99easier by sending us your contributions through [ pull requests] [ ] .
1010
11- Pull requests for bug fixes must be based on the oldest stable version's branch
12- whereas pull requests for new features must be based on the ` master ` branch.
13-
1411Due to time constraints, we are not always able to respond as quickly as we
15- would like. Please do not take delays personal and feel free to remind us here,
16- on IRC, or on Gitter if you feel that we forgot to respond.
17-
18- Please see the [ project documentation] [ ] before proceeding. You should also know
19- about [ PHP-FIG] [ ] 's standards and basic unit testing, but we're sure you can
20- learn that just by looking at other validators. Pick the simple ones like ` ArrayType `
21- to begin.
12+ would like. Please do not take delays personally.
2213
2314Before writing anything, feature or bug fix:
2415
@@ -28,7 +19,7 @@ Before writing anything, feature or bug fix:
2819 to work on that;
2920 - If there is, create a comment to notify everybody that you're going to
3021 work on that.
31- - Make sure that what you need is not done yet
22+ - Make sure that what you need is not done yet.
3223
3324## Adding a new validator
3425
@@ -40,10 +31,9 @@ A common validator on Respect\Validation is composed of three classes:
4031The classes are pretty straightforward. In the sample below, we're going to
4132create a validator that validates if a string is equal to "Hello World".
4233
43- - Classes should be ` final ` unless they are used in a different scope;
44- - Properties should be ` private ` unless they are used in a different scope;
45- - Classes should use strict typing;
46- - Some docblocks are required.
34+ - Validator classes should be ` final ` whenever possible.
35+ - Validator classes should ` readonly ` whenever possible.
36+ - Properties should be ` private ` and ` readonly ` whenever possible.
4737
4838### Creating the validator
4939
@@ -75,7 +65,7 @@ use Respect\Validation\Validators\Core\Simple;
7565 '{{subject}} must be a Hello World',
7666 '{{subject}} must not be a Hello World',
7767)]
78- final class HelloWorld extends Simple
68+ final readonly class HelloWorld extends Simple
7969{
8070 protected function isValid(mixed $input): bool
8171 {
@@ -90,10 +80,8 @@ Finally, we need to test if everything is running smooth. We have `RuleTestCase`
9080that allows us to make easier to test validators, but you fell free to use the
9181` PHPUnit\Framework\TestCase ` if you want or you need it's necessary.
9282
93- The ` RuleTestCase ` extends PHPUnit's ` PHPUnit\Framework\TestCase ` class, so you
94- are able to use any methods of it. By extending ` RuleTestCase ` you should
95- implement two methods that should return a [ data provider] [ ] with the validator as
96- first item of the arrays:
83+ The ` RuleTestCase ` extends PHPUnit's ` PHPUnit\Framework\TestCase ` class with
84+ conventional [ data provider] [ ] methods:
9785
9886- ` providerForValidInput ` : Will test when ` validate() ` should return ` true `
9987- ` providerForInvalidInput ` : Will test when ` validate() ` should return ` false `
@@ -142,60 +130,49 @@ for it other than what is covered by `RuleTestCase`.
142130
143131### Helping us a little bit more
144132
145- Your validator will be accepted only with these 3 files (validator and unit test),
146- but if you really want to help us, you can follow the example of [ ArrayType] [ ] by:
147-
148- - Adding your new validator on the ` Validator ` 's class docblock;
149- - Writing a documentation for your new validator;
150- - Creating integration tests with PHPT.
133+ You should include documentation to your new validator. A minimal document
134+ is acceptable. You can use ` bin/console lint:docs ` to help you ensure that
135+ document follows our conventions. ` bin/console lint:docs --fix ` will even
136+ fix some common mistakes automatically.
151137
152- As we already said, none of them are required but you will help us a lot.
138+ Additionally, consider adding a feature test to ` tests/feature ` . Those help
139+ us track common use cases and usage patterns.
153140
154141## Documentation
155142
156143Our docs at https://respect-validation.readthedocs.io are generated from our
157144Markdown files. Add your brand new validator and it should be soon available.
158145
159- ## Running Tests
146+ You can preview how the docs will look like by running ` composer docs-serve ` .
160147
161- After run ` composer install ` on the library's root directory you must run PHPUnit.
148+ ## Running Checks
162149
163- ### Linux
150+ After run ` composer install ` on the library's root directory you must run
151+ ` composer qa ` .
164152
165- You can test the project using the commands:
153+ This alias will run several checks, including unit tests, static analysis
154+ and more.
166155
167- ``` sh
168- $ vendor/bin/phpunit
169- ```
170-
171- or
156+ Check out the ` scripts ` section on ` composer.json ` for more details on which
157+ checks are performed.
172158
173- ``` sh
174- $ composer phpunit
175- ```
159+ ## Benchmarks
176160
177- ### Windows
161+ If you want to improve the project performance or make sure your change doesn't
162+ introduce a performance regression, you can use our standard benchmark suite
163+ at ` tests/benchmark ` .
178164
179- You can test the project using the commands:
180-
181- ``` sh
182- > vendor\b in\p hpunit
183- ```
184-
185- or
186-
187- ``` sh
188- > composer phpunit
189- ```
165+ Typical workflow:
190166
191- No test should fail.
167+ - (Optional) Write a new benchmark in ` tests/benchmark ` .
168+ - Run ` vendor/bin/phpbench run --tag=before ` before making a change.
169+ - Change the code as you like.
170+ - Run ` vendor/bin/phpbench run --ref=before ` to compare performance with the
171+ tagged run.
192172
193- You can tweak the PHPUnit's settings by copying ` phpunit.xml.dist ` to ` phpunit.xml `
194- and changing it according to your needs .
173+ Check out the [ phpbench documentation ] ( https://phpbench.readthedocs.io/en/latest/index.html )
174+ for more information .
195175
196- [ ArrayType ] : https://github.com/Respect/Validation/commit/f08a1fa
197- [ data provider ] : https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers " PHPUnit Data Providers "
176+ [ data provider ] : https://docs.phpunit.de/en/12.5/writing-tests-for-phpunit.html#data-providers " PHPUnit Data Providers "
198177[ open an issue ] : http://github.com/Respect/Validation/issues
199- [ PHP-FIG ] : http://www.php-fig.org " PHP Framework Interop Group "
200- [ project documentation ] : https://respect-validation.readthedocs.io/ " Respect\\ Validation documentation "
201178[ pull requests ] : http://help.github.com/pull-requests " GitHub pull requests "
0 commit comments