From d2cb2f188eeb60a458df38fdc91c3f2923e614e8 Mon Sep 17 00:00:00 2001 From: Tonko Mulder Date: Wed, 30 Jul 2025 21:20:43 +0200 Subject: [PATCH 1/2] add an section about loading additional config for tests closes #1443 --- .../content/1.x/1-essentials/07-testing.md | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Web/Documentation/content/1.x/1-essentials/07-testing.md b/src/Web/Documentation/content/1.x/1-essentials/07-testing.md index db9d7ffa..0da50090 100644 --- a/src/Web/Documentation/content/1.x/1-essentials/07-testing.md +++ b/src/Web/Documentation/content/1.x/1-essentials/07-testing.md @@ -38,13 +38,39 @@ final class HomeControllerTest extends IntegrationTestCase } ``` +## Additional configuration + +By default, only the entries inside the `require` key of the `composer.json` file are discovered. +As such if the tests need additional configuration, these locations need to be discovered manually. +In which case you may add these locations to the `discoveryLocations` property of the `IntegrationTestCase` class. + +For example `tests/Config` contains configuration that is only needed for tests, like database configuration. + +```php tests/IntegrationTestCase.php +use Tempest\Core\DiscoveryLocation; + +final class IntegrationTestCase extends TestCase +{ + protected string $root = __DIR__ . '/../'; + + protected function setUp(): void + { + $this->discoveryLocations = [ + new DiscoveryLocation(namespace: 'Tests\\Config', path: __DIR__ . '/Config'), + ]; + + parent::setUp(); + } +} +``` + ## Changing the location of tests The `phpunit.xml` file contains a `{html}` element that configures the directory in which PHPUnit looks for test files. This may be changed to follow any rule of your convenience. For instance, you may colocate test files and their corresponding class by changing the `{html}suffix` attribute in `phpunit.xml` to the following: -```diff +```diff phpunit.xml - ./tests From 8476babd73ead54b09065d61de7b9784cd7fb1d6 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Thu, 31 Jul 2025 01:08:42 +0200 Subject: [PATCH 2/2] chore: update phrasing --- .../content/1.x/1-essentials/07-testing.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Web/Documentation/content/1.x/1-essentials/07-testing.md b/src/Web/Documentation/content/1.x/1-essentials/07-testing.md index 0da50090..06e40e50 100644 --- a/src/Web/Documentation/content/1.x/1-essentials/07-testing.md +++ b/src/Web/Documentation/content/1.x/1-essentials/07-testing.md @@ -38,13 +38,11 @@ final class HomeControllerTest extends IntegrationTestCase } ``` -## Additional configuration +## Test-specific discovery locations -By default, only the entries inside the `require` key of the `composer.json` file are discovered. -As such if the tests need additional configuration, these locations need to be discovered manually. -In which case you may add these locations to the `discoveryLocations` property of the `IntegrationTestCase` class. +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. -For example `tests/Config` contains configuration that is only needed for tests, like database configuration. +For instance, you may create a `tests/config` directory that contains test-specific configuration files, and instruct Tempest to discover them: ```php tests/IntegrationTestCase.php use Tempest\Core\DiscoveryLocation; @@ -56,7 +54,7 @@ final class IntegrationTestCase extends TestCase protected function setUp(): void { $this->discoveryLocations = [ - new DiscoveryLocation(namespace: 'Tests\\Config', path: __DIR__ . '/Config'), + new DiscoveryLocation(namespace: 'Tests\\Config', path: __DIR__ . '/config'), ]; parent::setUp();