Skip to content

Commit 92413ba

Browse files
committed
Add configuration docs
1 parent 84fcfe7 commit 92413ba

10 files changed

Lines changed: 392 additions & 20 deletions

docs/benchmarks.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Benchmarks
2+
3+
::: info
4+
This functionality is provided by the `\Testo\Bench\BenchmarkPlugin` plugin, included in the `SuitePlugins` default set.
5+
:::

docs/configuration.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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.

docs/getting-started.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ return new ApplicationConfig(
4444
),
4545
),
4646
new SuiteConfig(
47-
name: 'Source',
47+
name: 'Sources',
4848
location: new FinderConfig(
4949
include: ['src'],
5050
),
51+
plugins: SuitePlugins::only(
52+
new InlineTestPlugin(),
53+
new BenchmarkPlugin(),
54+
),
5155
),
5256
],
5357
);
5458
```
5559

56-
In this example we defined two test suites: `Unit` for unit tests located in `tests/Unit`, and `Source` for [inline tests](inline-tests.md) and benchmarks right in the source code in the `src` folder.
60+
In this example we defined two test suites: `Unit` for unit tests located in `tests/Unit`, and `Sources` for [inline tests](inline-tests.md) and [benchmarks](benchmarks.md) right in the project source code, in the `src` folder.
61+
62+
To learn more about configuration, visit the [Configuration](configuration.md) section.
5763

5864
## Writing Your First Test
5965

docs/lifecycle.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ llms_description: "#[BeforeEach], #[AfterEach], #[BeforeAll], #[AfterAll] lifecy
44

55
# Lifecycle
66

7-
Lifecycle attributes define setup and teardown methods that run automatically at specific points during test execution.
7+
Lifecycle attributes let you run code before and after tests — for setting up the environment, cleaning up state, and managing resources.
8+
9+
::: info
10+
This functionality is provided by the `\Testo\Lifecycle\LifecyclePlugin` plugin, included in the `SuitePlugins` default set.
11+
:::
812

913
## Class Instantiation
1014

docs/writing-tests.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ llms_description: "Overview of test declaration approaches: methods in classes,
44

55
# Writing Tests
66

7-
Testo doesn't care where a test lives, as long as it can be wrapped in a Closure.
7+
Testo doesn't care where a test lives, as long as it can be executed.
88

99
## Where to Write Tests
1010

1111
- **In methods** — in regular classes without `TestCase` inheritance.
1212
- **In functions** — in standalone functions outside classes.
13-
- **In attributes** — directly on the method being tested. See [Inline Tests](./inline-tests).
13+
- **In attributes** — directly on the method being tested. See [Inline Tests](inline-tests.md).
1414

1515
## Test Discovery
1616

17-
Depending on the configuration, Testo can discover tests in several ways:
17+
Depending on the configured [plugins](plugins.md), Testo can discover tests in several ways:
1818

19-
- **Explicit** — the [#\[Test\] attribute](./test-attribute) marks a method, function, or class.
20-
- **Conventions**[naming patterns](./naming-conventions) like `testSomething()` methods or `*Test` classes.
21-
- **Custom strategies** — you can implement your own test discovery, for example by function-call (like PEST, but without execution) or by class parent, like PHPUnit.
19+
- **Explicit** — the [#\[Test\] attribute](test-attribute.md) marks a method, function, or class.
20+
- **Conventions**[naming patterns](naming-conventions.md) like `testSomething()` methods or `*Test` classes.
21+
- **Custom strategies** — you can implement your own test discovery, for example by function-call (like PEST) or by class parent, like PHPUnit.
2222

2323
All approaches can be combined in one project or even in one Test Suite.
2424

2525
## Less Code
2626

27-
- **Parameterization** — instead of copying a test for each data set, write one test and pass it different values via [data providers](./data-providers).
27+
- **Parameterization** — instead of copying a test for each data set, write one test and pass it different values via [data providers](data-providers.md).
2828
- **Interceptor attributes** — extract repetitive boilerplate into reusable attributes.

ru/docs/benchmarks.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Бенчмарки
2+
3+
::: info
4+
За эту функциональность отвечает плагин `\Testo\Bench\BenchmarkPlugin`, входящий в набор `SuitePlugins` по умолчанию.
5+
:::

0 commit comments

Comments
 (0)