You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/configuration.md
+15-10Lines changed: 15 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
By default, if no configuration file is provided, Testo will run tests from the `tests` folder with the default plugin set.
4
4
5
-
To customize the configuration, create a `testo.php` file in the root of your project. The file must return an `ApplicationConfig` instance:
5
+
To configure Testo, create a `testo.php` file in the root of your project. The file must return an `ApplicationConfig` instance:
6
6
7
7
```php
8
8
<?php
@@ -16,7 +16,6 @@ return new ApplicationConfig(
16
16
suites: [
17
17
new SuiteConfig(
18
18
name: 'Unit',
19
-
parallel: true,
20
19
location: ['tests/Unit'],
21
20
),
22
21
new SuiteConfig(
@@ -32,7 +31,6 @@ return new ApplicationConfig(
32
31
The root configuration object:
33
32
34
33
-`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
34
-`plugins` — application-level plugins. Loaded before Test Suites and act globally (see [Plugins](#plugins) section).
37
35
38
36
All parameters and their default values are described in the class itself — your IDE will show hints.
@@ -60,7 +58,7 @@ new SuiteConfig(
60
58
),
61
59
```
62
60
63
-
::: tip
61
+
::: info
64
62
Arrays in `location` and `plugins` are shorthands for `new FinderConfig(include: ...)` and `SuitePlugins::with(...)`. For more flexible configuration, use `FinderConfig` and `SuitePlugins` directly.
65
63
:::
66
64
@@ -89,15 +87,22 @@ Testo is built on [plugins](plugins.md) — they define how tests are discovered
89
87
If the `plugins` array is not specified, Testo uses the default plugin set.
90
88
91
89
::: question Which application plugins are enabled by default?
92
-
-[FilterPlugin](plugins/filter.md)
93
-
- TerminalPlugin
94
-
- TeamcityPlugin
90
+
You can check the default plugin list in the `ApplicationPlugins` class.
91
+
92
+
Currently:
93
+
-[Filter](plugins/filter.md)
94
+
-**Terminal** and **Teamcity** depending on the `--teamcity` flag
95
95
:::
96
96
97
97
::: question Which Test Suite plugins are enabled by default?
98
-
-[LifecyclePlugin](plugins/lifecycle.md)
99
-
-[InlineTestPlugin](plugins/inline.md)
100
-
-[BenchmarkPlugin](plugins/bench.md)
98
+
You can check the default plugin list in the `SuitePlugins` class.
By default, if no configuration file is provided, Testo will run tests from the `tests` folder.
26
26
27
-
To customize the configuration, create a `testo.php` file in the root of your project:
27
+
To configure Testo, create a `testo.php` file in the root of your project:
28
28
29
29
```php
30
30
<?php
@@ -39,19 +39,11 @@ return new ApplicationConfig(
39
39
suites: [
40
40
new SuiteConfig(
41
41
name: 'Unit',
42
-
location: new FinderConfig(
43
-
include: ['tests/Unit'],
44
-
),
42
+
location: ['tests/Unit'],
45
43
),
46
44
new SuiteConfig(
47
45
name: 'Sources',
48
-
location: new FinderConfig(
49
-
include: ['src'],
50
-
),
51
-
plugins: SuitePlugins::only(
52
-
new InlineTestPlugin(),
53
-
new BenchmarkPlugin(),
54
-
),
46
+
location: ['src'],
55
47
),
56
48
],
57
49
);
@@ -63,54 +55,49 @@ To learn more about configuration, visit the [Configuration](configuration.md) s
63
55
64
56
## Writing Your First Test
65
57
66
-
Create a test class in the configured test directory (e.g., `tests/Unit/CalculatorTest.php`):
58
+
Create a test class in the configured directory (e.g., `tests/Unit/MyFirstTest.php`) and add a method with the `#[Test]` attribute:
67
59
68
60
```php
69
-
<?php
70
-
71
-
declare(strict_types=1);
72
-
73
-
namespace Tests\Unit;
74
-
75
-
use Testo\Assert;
76
-
use Testo\Assert\ExpectException;
77
-
use Testo\Application\Attribute\Test;
78
-
use Testo\Retry\RetryPolicy;
79
-
80
-
final class CalculatorTest
61
+
final class MyFirstTest
81
62
{
82
63
#[Test]
83
64
public function dividesNumbers(): void
84
65
{
85
66
$result = 10 / 2;
86
67
87
-
Assert::same(5.0, $result);
88
-
Assert::notSame(5, $result); // Types matter!
68
+
Assert::same($result, 5.0);
69
+
Assert::notSame($result, 5); // Types matter
89
70
}
71
+
}
72
+
```
90
73
91
-
#[Test]
92
-
#[RetryPolicy(maxAttempts: 3)] // Retries up to 3 times if test fails
93
-
public function flakyApiCall(): void
94
-
{
95
-
$response = $this->makeExternalApiCall();
74
+
The `#[Test]` attribute marks the method as a test, and the `Assert` facade checks assertions.
75
+
Testo supports a wide range of assertions via `Assert` and expectations via `Expect`.
76
+
77
+
Use attributes to extend test functionality.
78
+
For example, `#[Retry]` retries a test on failure, and `#[ExpectException]` expects a specific exception:
96
79
97
-
Assert::same(200, $response->status);
80
+
```php
81
+
#[Test]
82
+
final class MyFirstTest
83
+
{
84
+
#[Retry(maxAttempts: 5)] // Retries up to 5 times if test fails
85
+
public function flakyTest(): void
86
+
{
87
+
Assert::same(mt_rand(0, 2), 2);
98
88
}
99
89
100
-
#[Test]
101
90
#[ExpectException(\RuntimeException::class)]
102
-
public function throwsException(): void
91
+
public function throwsException(): never
103
92
{
104
93
throw new \RuntimeException('Expected error');
105
94
}
106
95
}
107
96
```
108
97
109
-
### Key Points
110
-
111
-
- The `#[Test]` attribute marks test methods, and test classes don't need to inherit from a base class. See [Writing Tests](./writing-tests) for more options.
112
-
- Use the `Assert` facade for assertions and `Expect` for expectations.
113
-
- Testo provides multiple attributes to extend testing capabilities (retry policies, exception handling, and more).
98
+
::: question Why `#[Test]` on a class?
99
+
You can put `#[Test]` on a class — then all public methods with return type `void` or `never` become tests.
100
+
:::
114
101
115
102
## Running Tests
116
103
@@ -124,7 +111,9 @@ You should see output showing the test results with detailed information about p
124
111
125
112
## IDE Support
126
113
127
-
Testo comes with an official [IDEA plugin](https://plugins.jetbrains.com/plugin/28842-testo) for PhpStorm and IntelliJ IDEA.
114
+
Testo comes with an official IDEA plugin for PhpStorm and IntelliJ IDEA.
0 commit comments