Data Providers
Sometimes tests need to make the same assertions over many different types of data. Using #[DataProvider] can help reduce the amount of test duplication when you encounter this scenario.
<?php
use Cspray\Labrador\AsyncUnit\TestCase;
use Cspray\Labrador\AsyncUnit\Attribute\Test;
use Cspray\Labrador\AsyncUnit\Attribute\DataProvider;
class MyDataProviderTestCase extends TestCase {
public function myData() : array {
return [
['async unit', 'phpunit'],
['AsyncUnit', 'AsyncUnit'],
['AsyncUnit', 'async unit']
];
}
#[Test]
#[DataProvider('myData')]
public function checkStringsAreEqual(string $expected, string $actual) : void {
$this->assert()->stringEquals($expected, $actual);
}
}Last updated
Was this helpful?