# Data Providers

When a test needs to make the same assertion across a variety of data a *data provider* can reduce the amount of duplication necessary to write the appropriate tests. A data provider is a public method on the `TestCase` that returns an array of arrays with the appropriate arguments for the test. The test needing to use the data provider should be annotated with the `#[DataProvider]` Attribute and define parameters on its method signature.

```php
<?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);
    }

}
```

Each set of arguments will have its own `TestCase` instance and will have all of the appropriate test hooks invoked.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.labrador-kennel.io/async-unit/tutorials/data-providers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
