11<?php
22
3- declare (strict_types=1 );
4-
5- namespace Respect \Validation \Benchmarks ;
6-
73/*
84 * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
95 * SPDX-License-Identifier: MIT
106 */
117
12- use Generator ;
8+ declare (strict_types=1 );
9+
10+ namespace Respect \Validation \Benchmarks ;
11+
1312use PhpBench \Attributes as Bench ;
13+ use Respect \Validation \Test \SmokeTestProvider ;
1414use Respect \Validation \Validator ;
15- use Respect \Validation \ValidatorBuilder as v ;
1615
1716class ValidatorBench
1817{
19- /** @param array<Validator, mixed> $params */ #[Bench \Iterations(10 )]
18+ use SmokeTestProvider;
19+
20+ /** @param array<Validator, mixed> $params */
21+ #[Bench \Iterations(10 )]
2022 #[Bench \RetryThreshold(10 )]
2123 #[Bench \Revs(5 )]
2224 #[Bench \ParamProviders(['provideValidatorInput ' ])]
@@ -25,91 +27,4 @@ public function benchValidate(array $params): void
2527 [$ v , $ input ] = $ params ;
2628 $ v ->validate ($ input );
2729 }
28-
29- public function provideValidatorInput (): Generator
30- {
31- yield 'AllOf ' => [v::allOf (v::intVal (), v::greaterThan (0 )), 5 ];
32- yield 'Alnum ' => [v::alnum (), 'abc123 ' ];
33- yield 'Alpha ' => [v::alpha (), 'abc ' ];
34- yield 'AnyOf ' => [v::anyOf (v::intVal (), v::stringVal ()), 5 ];
35- yield 'ArrayType ' => [v::arrayType (), []];
36- yield 'ArrayVal ' => [v::arrayVal (), []];
37- yield 'Between ' => [v::between (1 , 10 ), 5 ];
38- yield 'BetweenExclusive ' => [v::betweenExclusive (1 , 10 ), 5 ];
39- yield 'BoolType ' => [v::boolType (), true ];
40- yield 'BoolVal ' => [v::boolVal (), true ];
41- yield 'Bsn ' => [v::bsn (), '612890053 ' ];
42- yield 'Call ' => [v::call ('array_keys ' , v::each (v::stringType ())), ['a ' => 'b ' ]];
43- yield 'Charset ' => [v::charset ('UTF-8 ' ), 'example ' ];
44- yield 'Circuit ' => [v::circuit (v::intVal (), v::trueVal ()), 123 ];
45- yield 'Cnpj ' => [v::cnpj (), '11444777000161 ' ];
46- yield 'Consonant ' => [v::consonant (), 'bcdf ' ];
47- yield 'Contains ' => [v::contains ('needle ' ), 'haystack needle ' ];
48- yield 'ContainsAny ' => [v::containsAny (['a ' , 'b ' ]), 'abc ' ];
49- yield 'ContainsCount ' => [v::containsCount ('a ' , 3 ), 'banana ' ];
50- yield 'Control ' => [v::control (), "\n\r" ];
51- yield 'Countable ' => [v::countable (), []];
52- yield 'CountryCode ' => [v::countryCode (), 'US ' ];
53- yield 'Cpf ' => [v::cpf (), '11598647644 ' ];
54- yield 'CurrencyCode ' => [v::currencyCode (), 'USD ' ];
55- yield 'Date ' => [v::date (), '2020-01-01 ' ];
56- yield 'DateTime ' => [v::dateTime (), '2020-01-01 12:00:00 ' ];
57- yield 'Decimal ' => [v::decimal (2 ), '1.23 ' ];
58- yield 'Digit ' => [v::digit (), '7 ' ];
59- yield 'Domain ' => [v::domain (), 'example.com ' ];
60- yield 'Each ' => [v::each (v::stringType ()), ['a ' , 'b ' ]];
61- yield 'Email ' => [v::email (), 'bob@example.com ' ];
62- yield 'EndsWith ' => [v::endsWith ('.com ' ), 'example.com ' ];
63- yield 'Equals ' => [v::equals ('x ' ), 'x ' ];
64- yield 'Even ' => [v::even (), 2 ];
65- yield 'Executable ' => [v::executable (), 'tests/fixtures/executable ' ];
66- yield 'Exists ' => [v::exists (), 'tests/fixtures/valid-image.png ' ];
67- yield 'FalseVal ' => [v::falseVal (), false ];
68- yield 'Fibonacci ' => [v::fibonacci (), 13 ];
69- yield 'File ' => [v::file (), __FILE__ ];
70- yield 'FloatType ' => [v::floatType (), 1.23 ];
71- yield 'FloatVal ' => [v::floatVal (), 1.23 ];
72- yield 'GreaterThan ' => [v::greaterThan (0 ), 1 ];
73- yield 'GreaterThanOrEqual ' => [v::greaterThanOrEqual (1 ), 1 ];
74- yield 'Hetu ' => [v::hetu (), '010106A9012 ' ];
75- yield 'Iban ' => [v::iban (), 'SE35 5000 0000 0549 1000 0003 ' ];
76- yield 'Identical ' => [v::identical (123 ), 123 ];
77- yield 'In ' => [v::in (['a ' , 'b ' ]), 'a ' ];
78- yield 'IntType ' => [v::intType (), 123 ];
79- yield 'IntVal ' => [v::intVal (), 123 ];
80- yield 'Ip ' => [v::ip (), '127.0.0.1 ' ];
81- yield 'IterableVal ' => [v::iterableVal (), []];
82- yield 'LanguageCode ' => [v::languageCode (), 'en ' ];
83- yield 'LessThan ' => [v::lessThan (10 ), 5 ];
84- yield 'LessThanOrEqual ' => [v::lessThanOrEqual (10 ), 10 ];
85- yield 'Lowercase ' => [v::lowercase (), 'abc ' ];
86- yield 'Luhn ' => [v::luhn (), '2222400041240011 ' ];
87- yield 'MacAddress ' => [v::macAddress (), '00:11:22:33:44:55 ' ];
88- yield 'Negative ' => [v::negative (), -1 ];
89- yield 'Nip ' => [v::nip (), '1645865777 ' ];
90- yield 'Not ' => [v::not (v::trueVal ()), false ];
91- yield 'NullType ' => [v::nullType (), null ];
92- yield 'NumericVal ' => [v::numericVal (), '123 ' ];
93- yield 'Odd ' => [v::odd (), 3 ];
94- yield 'PerfectSquare ' => [v::perfectSquare (), 16 ];
95- yield 'Pesel ' => [v::pesel (), '21120209256 ' ];
96- yield 'Property ' => [v::property ('email ' , v::endsWith ('@example.com ' )), (object ) ['email ' => 'a@example.com ' ]];
97- yield 'PropertyExists ' => [v::propertyExists ('email ' ), (object ) ['email ' => 'a@example.com ' ]];
98- yield 'PropertyOptional ' => [v::propertyOptional ('missing ' , v::email ()), (object ) ['email ' => 'a@example.com ' ]];
99- yield 'Readable ' => [v::readable (), 'tests/fixtures/valid-image.png ' ];
100- yield 'ScalarVal ' => [v::scalarVal (), 'example ' ];
101- yield 'Slug ' => [v::slug (), 'a-valid-slug ' ];
102- yield 'StartsWith ' => [v::startsWith ('ex ' ), 'example ' ];
103- yield 'StringType ' => [v::stringType (), 'example ' ];
104- yield 'StringVal ' => [v::stringVal (), 'example ' ];
105- yield 'SymbolicLink ' => [v::symbolicLink (), 'tests/fixtures/symbolic-link ' ];
106- yield 'Time ' => [v::time (), '12:34:56 ' ];
107- yield 'TrueVal ' => [v::trueVal (), true ];
108- yield 'Unique ' => [v::unique (), [1 , 2 , 3 ]];
109- yield 'Uppercase ' => [v::uppercase (), 'ABC ' ];
110- yield 'Uuid ' => [v::uuid (), '123e4567-e89b-12d3-a456-426655440000 ' ];
111- yield 'When ' => [v::when (v::trueVal (), v::intVal ()), 123 ];
112- yield 'Writable ' => [v::writable (), 'tests/fixtures/valid-image.png ' ];
113- yield 'Xdigit ' => [v::xdigit (), 'AF ' ];
114- }
11530}
0 commit comments