respect-validation/tests/benchmark/IsoCodesBench.php
Alexandre Gomes Gaigalas d8e31dbc3a Containerize sokil databases
The main focus of this change is to make those optional dependencies
more testable.

Unfortunately, some phpstan-ignores had to be included, since ::set
is not a PsrContainer method. We're only using it on tests though,
so it's fine. It targets our php-di container for testing purposes
only. The real implementation only relies on ::get.

This change also has the side effect of improving the performance
of those validators by not instantiating their databases each time
a iso validator is built, achieving massive improvements in those
scenarios. A small benchmark with no assertions was added to track
that improvement.
2026-01-29 19:29:51 +00:00

69 lines
1.5 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
*/
declare(strict_types=1);
namespace Respect\Validation\Benchmarks;
use PhpBench\Attributes as Bench;
use Respect\Validation\Test\SmokeTestProvider;
use Respect\Validation\ValidatorBuilder;
class IsoCodesBench
{
use SmokeTestProvider;
#[Bench\Iterations(10)]
#[Bench\RetryThreshold(5)]
#[Bench\Revs(5)]
#[Bench\Warmup(1)]
#[Bench\Subject]
public function subdivisionCode(): void
{
ValidatorBuilder::subdivisionCode('US')->evaluate('CA');
}
#[Bench\Iterations(10)]
#[Bench\RetryThreshold(5)]
#[Bench\Revs(5)]
#[Bench\Warmup(1)]
#[Bench\Subject]
public function countryCode(): void
{
ValidatorBuilder::countryCode()->evaluate('US');
}
#[Bench\Iterations(10)]
#[Bench\RetryThreshold(5)]
#[Bench\Revs(5)]
#[Bench\Warmup(1)]
#[Bench\Subject]
public function currencyCode(): void
{
ValidatorBuilder::currencyCode()->evaluate('USD');
}
#[Bench\Iterations(10)]
#[Bench\RetryThreshold(5)]
#[Bench\Revs(5)]
#[Bench\Warmup(1)]
#[Bench\Subject]
public function languageCode(): void
{
ValidatorBuilder::languageCode()->evaluate('en');
}
#[Bench\Iterations(10)]
#[Bench\RetryThreshold(5)]
#[Bench\Revs(5)]
#[Bench\Warmup(1)]
#[Bench\Subject]
public function phone(): void
{
ValidatorBuilder::phone('US')->evaluate('+1 202-555-0125');
}
}