PHP code example of rasuvaeff / property-testing-testo
1. Go to this page and download the library: Download rasuvaeff/property-testing-testo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rasuvaeff / property-testing-testo example snippets
use Rasuvaeff\PropertyTesting\Assume;
use Rasuvaeff\PropertyTesting\Gen;
use Rasuvaeff\PropertyTesting\Property;
use Testo\Assert;
use Testo\Test;
#[Test]
final class RetryPolicyPropertyTest
{
#[Property(runs: 500)]
public function delayNeverExceedsCap(int $baseSeconds, int $cap, int $attempts): void
{
Assume::that($cap >= $baseSeconds);
$policy = RetryPolicy::exponential($baseSeconds, $cap);
Assert::true($policy->nextDelaySeconds($attempts) <= $cap);
}
/** @return array<string, \Rasuvaeff\PropertyTesting\ArbitraryInterface> */
public static function delayNeverExceedsCapGenerators(): array
{
return [
'baseSeconds' => Gen::intBetween(1, 300),
'cap' => Gen::intBetween(1, 86_400),
'attempts' => Gen::intBetween(1, 100),
];
}
}
final readonly class DelayGenerators
{
/** @return array<string, \Rasuvaeff\PropertyTesting\ArbitraryInterface> */
public function __invoke(): array
{
return [
'base' => Gen::intBetween(1, 300),
'cap' => Gen::intBetween(1, 86_400),
];
}
}
#[Property(generators: new DelayGenerators())]
public function delayNeverExceedsCap(int $base, int $cap): void
{
}
/**
* @param int<1, 300> $base
* @param int<1, 86400> $cap
*/
#[Property(auto: true)]
public function delayNeverExceedsCap(int $base, int $cap): void
{
}
/** @param int<1, 40> $attempt */
#[Property(generators: 'provide', auto: true)]
public function delayIsMonotonic(float $multiplier, int $attempt): void { /* … */ }
/** @return array<string, ArbitraryInterface> */
public static function provide(): array
{
return ['multiplier' => Gen::floatBetween(1.0, 4.0)]; // the rest is derived
}
#[Property(runs: 200)]
public function stackBehavesLikeItsModel(CommandSequence $sequence): void
{
StateMachine::check($sequence, static fn(): Stack => new Stack());
}
/** @return array<string, \Rasuvaeff\PropertyTesting\ArbitraryInterface> */
public static function stackBehavesLikeItsModelGenerators(): array
{
return ['sequence' => Gen::commands([], [
Gen::map(Gen::intBetween(0, 99), static fn(int $v): Command => new Push($v)),
Gen::constant(new Pop()),
])];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.