Skip to content

Commit b6e061e

Browse files
Treggatsinnocenzi
andauthored
feat(docs/testing): document manual discovery locations (#102)
Co-authored-by: Enzo Innocenzi <[email protected]>
1 parent ac6cac9 commit b6e061e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/Web/Documentation/content/1.x/1-essentials/07-testing.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,37 @@ final class HomeControllerTest extends IntegrationTestCase
3838
}
3939
```
4040

41+
## Test-specific discovery locations
42+
43+
Tempest does not discover files outside of the namespaces defined in the `require` object of `composer.json`. If you need Tempest to discover test-specific fixture files, you may specify paths using the `discoveryLocations` property of the provided `IntegrationTestCase` class.
44+
45+
For instance, you may create a `tests/config` directory that contains test-specific configuration files, and instruct Tempest to discover them:
46+
47+
```php tests/IntegrationTestCase.php
48+
use Tempest\Core\DiscoveryLocation;
49+
50+
final class IntegrationTestCase extends TestCase
51+
{
52+
protected string $root = __DIR__ . '/../';
53+
54+
protected function setUp(): void
55+
{
56+
$this->discoveryLocations = [
57+
new DiscoveryLocation(namespace: 'Tests\\Config', path: __DIR__ . '/config'),
58+
];
59+
60+
parent::setUp();
61+
}
62+
}
63+
```
64+
4165
## Changing the location of tests
4266

4367
The `phpunit.xml` file contains a `{html}<testsuite>` element that configures the directory in which PHPUnit looks for test files. This may be changed to follow any rule of your convenience.
4468

4569
For instance, you may colocate test files and their corresponding class by changing the `{html}suffix` attribute in `phpunit.xml` to the following:
4670

47-
```diff
71+
```diff phpunit.xml
4872
<testsuites>
4973
<testsuite name="Tests">
5074
- <directory suffix="Test.php">./tests</directory>

0 commit comments

Comments
 (0)