Skip to content

Commit d2cb2f1

Browse files
committed
add an section about loading additional config for tests
closes #1443
1 parent ac6cac9 commit d2cb2f1

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

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

41+
## Additional configuration
42+
43+
By default, only the entries inside the `require` key of the `composer.json` file are discovered.
44+
As such if the tests need additional configuration, these locations need to be discovered manually.
45+
In which case you may add these locations to the `discoveryLocations` property of the `IntegrationTestCase` class.
46+
47+
For example `tests/Config` contains configuration that is only needed for tests, like database configuration.
48+
49+
```php tests/IntegrationTestCase.php
50+
use Tempest\Core\DiscoveryLocation;
51+
52+
final class IntegrationTestCase extends TestCase
53+
{
54+
protected string $root = __DIR__ . '/../';
55+
56+
protected function setUp(): void
57+
{
58+
$this->discoveryLocations = [
59+
new DiscoveryLocation(namespace: 'Tests\\Config', path: __DIR__ . '/Config'),
60+
];
61+
62+
parent::setUp();
63+
}
64+
}
65+
```
66+
4167
## Changing the location of tests
4268

4369
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.
4470

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

47-
```diff
73+
```diff phpunit.xml
4874
<testsuites>
4975
<testsuite name="Tests">
5076
- <directory suffix="Test.php">./tests</directory>

0 commit comments

Comments
 (0)