|
| 1 | +# Configuration |
| 2 | + |
| 3 | +By default, if no configuration file is provided, Testo will run tests from the `tests` folder with the default plugin set. |
| 4 | + |
| 5 | +To customize the configuration, create a `testo.php` file in the root of your project. The file must return an `ApplicationConfig` instance: |
| 6 | + |
| 7 | +```php |
| 8 | +<?php |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +use Testo\Application\Config\ApplicationConfig; |
| 13 | +use Testo\Application\Config\SuiteConfig; |
| 14 | + |
| 15 | +return new ApplicationConfig( |
| 16 | + suites: [ |
| 17 | + new SuiteConfig( |
| 18 | + name: 'Unit', |
| 19 | + parallel: true, |
| 20 | + location: ['tests/Unit'], |
| 21 | + ), |
| 22 | + new SuiteConfig( |
| 23 | + name: 'Feature', |
| 24 | + location: ['tests/Feature'], |
| 25 | + ), |
| 26 | + ], |
| 27 | +); |
| 28 | +``` |
| 29 | + |
| 30 | +## ApplicationConfig |
| 31 | + |
| 32 | +The root configuration object: |
| 33 | + |
| 34 | +- `suites` — array of Test Suites. Must contain at least one element — an empty array will cause an error. |
| 35 | +- `src` — location of the project source code. Will be used for code coverage in the future. |
| 36 | +- `plugins` — application-level plugins. Loaded before Test Suites and act globally (see [Plugins](#plugins) section). |
| 37 | + |
| 38 | +All parameters and their default values are described in the class itself — your IDE will show hints. |
| 39 | + |
| 40 | +## SuiteConfig |
| 41 | + |
| 42 | +Configuration for a single Test Suite: name, test location, and plugin set. |
| 43 | + |
| 44 | +```php |
| 45 | +// Simple form — array |
| 46 | +new SuiteConfig( |
| 47 | + name: 'Unit', |
| 48 | + location: ['tests/Unit'], |
| 49 | + plugins: [new NamingConventionPlugin()], |
| 50 | +), |
| 51 | + |
| 52 | +// With customization — FinderConfig and SuitePlugins |
| 53 | +new SuiteConfig( |
| 54 | + name: 'Unit', |
| 55 | + location: new FinderConfig( |
| 56 | + include: ['tests/Unit'], |
| 57 | + exclude: ['tests/Unit/Stubs'], |
| 58 | + ), |
| 59 | + plugins: SuitePlugins::without(BenchmarkPlugin::class), |
| 60 | +), |
| 61 | +``` |
| 62 | + |
| 63 | +::: tip |
| 64 | +Arrays in `location` and `plugins` are shorthands for `new FinderConfig(include: ...)` and `SuitePlugins::with(...)`. For more flexible configuration, use `FinderConfig` and `SuitePlugins` directly. |
| 65 | +::: |
| 66 | + |
| 67 | +::: question Can I disable application-level plugins for a specific Test Suite? |
| 68 | +No, application-level plugins are loaded before Test Suites and act globally. |
| 69 | +::: |
| 70 | + |
| 71 | +## FinderConfig |
| 72 | + |
| 73 | +Defines the file search scope — which directories and files to include or exclude. Paths are relative to the project root. Glob patterns and regular expressions are not supported. |
| 74 | + |
| 75 | +```php |
| 76 | +new FinderConfig( |
| 77 | + include: ['tests'], |
| 78 | + exclude: ['tests/Fixtures', 'tests/Stubs'], |
| 79 | +) |
| 80 | +``` |
| 81 | + |
| 82 | +## Plugins |
| 83 | + |
| 84 | +Testo is built on [plugins](plugins.md) — they define how tests are discovered, executed, and processed. Plugins are registered at two levels: |
| 85 | + |
| 86 | +- **Application level** (`ApplicationConfig::$plugins`) — act globally across all Test Suites |
| 87 | +- **Test Suite level** (`SuiteConfig::$plugins`) — act only within a specific Test Suite |
| 88 | + |
| 89 | +If the `plugins` array is not specified, Testo uses the default plugin set. |
| 90 | + |
| 91 | +::: question Which application plugins are enabled by default? |
| 92 | +- [FilterPlugin](filtering.md) |
| 93 | +- TerminalPlugin |
| 94 | +- TeamcityPlugin |
| 95 | +::: |
| 96 | + |
| 97 | +::: question Which Test Suite plugins are enabled by default? |
| 98 | +- [LifecyclePlugin](lifecycle.md) |
| 99 | +- [InlineTestPlugin](inline-tests.md) |
| 100 | +- [BenchmarkPlugin](benchmarks.md) |
| 101 | +::: |
| 102 | + |
| 103 | +### Managing Plugins |
| 104 | + |
| 105 | +Use the `SuitePlugins` and `ApplicationPlugins` facades to configure plugins (identical API): |
| 106 | + |
| 107 | +::: code-group |
| 108 | +```php [with()] |
| 109 | +// Add NamingConventionPlugin to the default plugins |
| 110 | +// Other Test Suite plugins are preserved |
| 111 | +new SuiteConfig( |
| 112 | + plugins: SuitePlugins::with( |
| 113 | + new NamingConventionPlugin(), |
| 114 | + ), |
| 115 | +) |
| 116 | +``` |
| 117 | +```php [without()] |
| 118 | +// Remove BenchmarkPlugin from the default set |
| 119 | +// Other Test Suite plugins are preserved |
| 120 | +new SuiteConfig( |
| 121 | + plugins: SuitePlugins::without( |
| 122 | + BenchmarkPlugin::class, |
| 123 | + ), |
| 124 | +) |
| 125 | +``` |
| 126 | +```php [only()] |
| 127 | +// Only LifecyclePlugin — all others are disabled |
| 128 | +// Completely replaces the default set |
| 129 | +new SuiteConfig( |
| 130 | + plugins: SuitePlugins::only( |
| 131 | + new LifecyclePlugin(), |
| 132 | + ), |
| 133 | +) |
| 134 | +``` |
| 135 | +```php [Chaining] |
| 136 | +// Add one plugin and remove another |
| 137 | +// Methods can be chained together |
| 138 | +new SuiteConfig( |
| 139 | + plugins: SuitePlugins::with(new NamingConventionPlugin()) |
| 140 | + ->without(BenchmarkPlugin::class), |
| 141 | +) |
| 142 | +``` |
| 143 | +::: |
| 144 | + |
| 145 | +## Monorepo |
| 146 | + |
| 147 | +Since `suites` is a regular PHP array, configurations can be assembled from multiple modules. Each module has its own `testo.php` that works standalone and as a Test Suite source for the root config: |
| 148 | + |
| 149 | +```php |
| 150 | +// modules/billing/testo.php — works standalone |
| 151 | +return new ApplicationConfig( |
| 152 | + suites: [ |
| 153 | + new SuiteConfig( |
| 154 | + name: 'Billing', |
| 155 | + location: ['tests'], |
| 156 | + ), |
| 157 | + ], |
| 158 | +); |
| 159 | +``` |
| 160 | + |
| 161 | +```php |
| 162 | +// testo.php — root config assembles Test Suites from modules |
| 163 | +return new ApplicationConfig( |
| 164 | + suites: array_merge( |
| 165 | + (require 'modules/billing/testo.php')->suites, |
| 166 | + (require 'modules/shipping/testo.php')->suites, |
| 167 | + ), |
| 168 | +); |
| 169 | +``` |
| 170 | + |
| 171 | +Each module manages its own test configuration independently, while the root config runs everything together. |
0 commit comments