Skip to content

Commit 45a757a

Browse files
committed
Declare Lifecycle and Test attributes
1 parent 9fd7f73 commit 45a757a

4 files changed

Lines changed: 62 additions & 43 deletions

File tree

docs/plugins/lifecycle.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,25 @@ To control state between tests, use lifecycle attributes described below.
4949

5050
## Attributes
5151

52-
| Attribute | When it runs | How often |
53-
|-------------------------------------------|-------------------------------|--------------------|
54-
| <attr>\Testo\Lifecycle\BeforeTest</attr> | Before each test method | Once per test |
55-
| <attr>\Testo\Lifecycle\AfterTest</attr> | After each test method | Once per test |
56-
| <attr>\Testo\Lifecycle\BeforeClass</attr> | Before all tests in the class | Once per test case |
57-
| <attr>\Testo\Lifecycle\AfterClass</attr> | After all tests in the class | Once per test case |
52+
<signature h="3" compact name="#[\Testo\Lifecycle\BeforeTest(int $priority = 0)]">
53+
<short>Runs a method before each test in the class.</short>
54+
<param name="$priority">Execution priority. Higher values run first.</param>
55+
</signature>
56+
57+
<signature h="3" compact name="#[\Testo\Lifecycle\AfterTest(int $priority = 0)]">
58+
<short>Runs a method after each test in the class.</short>
59+
<param name="$priority">Execution priority. Higher values run first.</param>
60+
</signature>
61+
62+
<signature h="3" compact name="#[\Testo\Lifecycle\BeforeClass(int $priority = 0)]">
63+
<short>Runs a method once before all tests in the class. Suitable for expensive setup.</short>
64+
<param name="$priority">Execution priority. Higher values run first.</param>
65+
</signature>
66+
67+
<signature h="3" compact name="#[\Testo\Lifecycle\AfterClass(int $priority = 0)]">
68+
<short>Runs a method once after all tests in the class. Suitable for cleanup.</short>
69+
<param name="$priority">Execution priority. Higher values run first.</param>
70+
</signature>
5871

5972
## Execution Order
6073

docs/plugins/test.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ llms_description: "#[Test] attribute on classes, methods, and functions for expl
44

55
# Test Attribute
66

7-
The <attr>\Testo\Test</attr> attribute explicitly marks a method, function, or class as a test.
7+
The plugin discovers tests by the <attr>\Testo\Test()</attr> attribute. This is the primary way to explicitly declare a method, function, or class as a test.
88

9-
Can be placed on:
10-
11-
- **Class** — all public methods with `void` or `never` return type become tests
12-
- **Method** — only that method is a test
13-
- **Function** — the function is a test
9+
<plugin-info name="Test" class="\Testo\Test\TestPlugin" included="\Testo\Application\Config\Plugin\SuitePlugins" />
1410

11+
<signature h="2" name="#[\Testo\Test()]">
12+
<short>Explicitly marks a method, function, or class as a test.</short>
13+
<description>
14+
Can be used on **classes**, **methods**, and **functions**. When applied to a class (Test Case), all public methods with a `void` or `never` return type become tests. Otherwise, only the marked element becomes a test.
15+
</description>
16+
<example>
1517
::: code-group
1618
```php [#[Test] on class]
1719
// tests/Unit/Order.php
@@ -46,11 +48,5 @@ function calculates_total(): void { /* ... */ }
4648
function applies_discount(): void { /* ... */ }
4749
```
4850
:::
49-
50-
## When to Use
51-
52-
Use <attr>\Testo\Test</attr> when:
53-
54-
- You want **explicit** test declaration without relying on naming patterns
55-
- Your method/function name doesn't follow the `test` prefix convention
56-
- You prefer attribute-based discovery over convention-based
51+
</example>
52+
</signature>

ru/docs/plugins/lifecycle.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
outline: [2, 3]
3+
---
4+
15
# Жизненный цикл
26

37
Атрибуты жизненного цикла позволяют выполнять код до и после тестов — для подготовки окружения, очистки состояния и управления ресурсами.
@@ -45,12 +49,25 @@ final class ServiceTest
4549

4650
## Атрибуты
4751

48-
| Атрибут | Когда выполняется | Как часто |
49-
|-------------------------------------------|--------------------------------|----------------------------|
50-
| <attr>\Testo\Lifecycle\BeforeTest</attr> | Перед каждым тестовым методом | Один раз на тест |
51-
| <attr>\Testo\Lifecycle\AfterTest</attr> | После каждого тестового метода | Один раз на тест |
52-
| <attr>\Testo\Lifecycle\BeforeClass</attr> | Перед всеми тестами в классе | Один раз на тестовый класс |
53-
| <attr>\Testo\Lifecycle\AfterClass</attr> | После всех тестов в классе | Один раз на тестовый класс |
52+
<signature h="3" compact name="#[\Testo\Lifecycle\BeforeTest(int $priority = 0)]">
53+
<short>Выполняет метод перед каждым тестом в классе.</short>
54+
<param name="$priority">Приоритет выполнения. Чем больше значение, тем раньше выполняется метод.</param>
55+
</signature>
56+
57+
<signature h="3" compact name="#[\Testo\Lifecycle\AfterTest(int $priority = 0)]">
58+
<short>Выполняет метод после каждого теста в классе.</short>
59+
<param name="$priority">Приоритет выполнения. Чем больше значение, тем раньше выполняется метод.</param>
60+
</signature>
61+
62+
<signature h="3" compact name="#[\Testo\Lifecycle\BeforeClass(int $priority = 0)]">
63+
<short>Выполняет метод один раз перед всеми тестами в классе. Подходит для дорогой инициализации.</short>
64+
<param name="$priority">Приоритет выполнения. Чем больше значение, тем раньше выполняется метод.</param>
65+
</signature>
66+
67+
<signature h="3" compact name="#[\Testo\Lifecycle\AfterClass(int $priority = 0)]">
68+
<short>Выполняет метод один раз после всех тестов в классе. Подходит для очистки ресурсов.</short>
69+
<param name="$priority">Приоритет выполнения. Чем больше значение, тем раньше выполняется метод.</param>
70+
</signature>
5471

5572
## Порядок выполнения
5673

ru/docs/plugins/test.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
# Атрибут Test
22

3-
<plugin-info name="Test" class="\Testo\Test\TestPlugin" included="\Testo\Application\Config\Plugin\SuitePlugins" />
4-
5-
6-
Атрибут <attr>\Testo\Test</attr> явно помечает метод, функцию или класс как тест.
7-
8-
Можно ставить на:
3+
Плагин отвечает за обнаружение тестов по атрибуту <attr>\Testo\Test</attr>. Это основной способ явно объявить метод, функцию или класс тестом.
94

10-
- **Класс** — все публичные методы с возвращаемым типом `void` или `never` становятся тестами
11-
- **Метод** — только этот метод является тестом
12-
- **Функцию** — функция является тестом
5+
<plugin-info name="Test" class="\Testo\Test\TestPlugin" included="\Testo\Application\Config\Plugin\SuitePlugins" />
136

7+
<signature h="2" name="#[\Testo\Test()]">
8+
<short>Явно помечает метод, функцию или класс как тест.</short>
9+
<description>
10+
Можно использовать на **классах**, **методах** и **функциях**. В случае применения на классе (Test Case), все публичные методы с возвращаемым типом `void` или `never` становятся тестами. В остальных случаях, только помеченный элемент становится тестом.
11+
</description>
12+
<example>
1413
::: code-group
1514
```php [#[Test] на классе]
1615
// tests/Unit/Order.php
@@ -45,11 +44,5 @@ function calculates_total(): void { /* ... */ }
4544
function applies_discount(): void { /* ... */ }
4645
```
4746
:::
48-
49-
## Когда использовать
50-
51-
Используйте <attr>\Testo\Test</attr>, когда:
52-
53-
- Хотите **явно** объявлять тесты без привязки к именам
54-
- Имя метода/функции не следует конвенции с префиксом `test`
55-
- Предпочитаете обнаружение по атрибутам, а не по конвенциям
47+
</example>
48+
</signature>

0 commit comments

Comments
 (0)