@@ -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,8 @@ 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+ - Properties should be ` private ` and ` readonly ` whenever possible.
4736
4837### Creating the validator
4938
@@ -75,7 +64,7 @@ use Respect\Validation\Validators\Core\Simple;
7564 '{{subject}} must be a Hello World',
7665 '{{subject}} must not be a Hello World',
7766)]
78- final class HelloWorld extends Simple
67+ final readonly class HelloWorld extends Simple
7968{
8069 protected function isValid(mixed $input): bool
8170 {
@@ -90,10 +79,8 @@ Finally, we need to test if everything is running smooth. We have `RuleTestCase`
9079that allows us to make easier to test validators, but you fell free to use the
9180` PHPUnit\Framework\TestCase ` if you want or you need it's necessary.
9281
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:
82+ The ` RuleTestCase ` extends PHPUnit's ` PHPUnit\Framework\TestCase ` class with
83+ conventional [ data provider] [ ] methods:
9784
9885- ` providerForValidInput ` : Will test when ` validate() ` should return ` true `
9986- ` providerForInvalidInput ` : Will test when ` validate() ` should return ` false `
@@ -142,60 +129,49 @@ for it other than what is covered by `RuleTestCase`.
142129
143130### Helping us a little bit more
144131
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.
132+ You should include documentation to your new validator. A minimal document
133+ is acceptable. You can use ` bin/console lint:docs ` to help you ensure that
134+ document follows our conventions. ` bin/console lint:docs --fix ` will even
135+ fix some common mistakes automatically.
151136
152- As we already said, none of them are required but you will help us a lot.
137+ Additionally, consider adding a feature test to ` tests/feature ` . Those help
138+ us track common use cases and usage patterns.
153139
154140## Documentation
155141
156142Our docs at https://respect-validation.readthedocs.io are generated from our
157143Markdown files. Add your brand new validator and it should be soon available.
158144
159- ## Running Tests
145+ You can preview how the docs will look like by running ` composer docs-serve ` .
160146
161- After run ` composer install ` on the library's root directory you must run PHPUnit.
147+ ## Running Checks
162148
163- ### Linux
149+ After run ` composer install ` on the library's root directory you must run
150+ ` composer qa ` .
164151
165- You can test the project using the commands:
152+ This alias will run several checks, including unit tests, static analysis
153+ and more.
166154
167- ``` sh
168- $ vendor/bin/phpunit
169- ```
170-
171- or
155+ Check out the ` scripts ` section on ` composer.json ` for more details on which
156+ checks are performed.
172157
173- ``` sh
174- $ composer phpunit
175- ```
158+ ## Benchmarks
176159
177- ### Windows
160+ If you want to improve the project performance or make sure your change doesn't
161+ introduce a performance regression, you can use our standard benchmark suite
162+ at ` tests/benchmark ` .
178163
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- ```
164+ Typical workflow:
190165
191- No test should fail.
166+ - (Optional) Write a new benchmark in ` tests/benchmark ` .
167+ - Run ` vendor/bin/phpbench run --tag=before ` before making a change.
168+ - Change the code as you like.
169+ - Run ` vendor/bin/phpbench run --ref=before ` to compare performance with the
170+ tagged run.
192171
193- You can tweak the PHPUnit's settings by copying ` phpunit.xml.dist ` to ` phpunit.xml `
194- and changing it according to your needs .
172+ Check out the [ phpbench documentation ] ( https://phpbench.readthedocs.io/en/latest/index.html )
173+ for more information .
195174
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 "
175+ [ data provider ] : https://docs.phpunit.de/en/12.5/writing-tests-for-phpunit.html#data-providers " PHPUnit Data Providers "
198176[ 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 "
201177[ pull requests ] : http://help.github.com/pull-requests " GitHub pull requests "
0 commit comments