File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export default defineConfig({
5252 text : 'Writing Tests' ,
5353 link : '/docs/writing-tests' ,
5454 items : [
55+ { text : 'Test Attribute' , link : '/docs/test-attribute' } ,
5556 { text : 'Inline Tests' , link : '/docs/inline-tests' } ,
5657 ] ,
5758 } ,
@@ -102,6 +103,7 @@ export default defineConfig({
102103 text : 'Пишем тесты' ,
103104 link : '/ru/docs/writing-tests' ,
104105 items : [
106+ { text : 'Атрибут Test' , link : '/ru/docs/test-attribute' } ,
105107 { text : 'Встроенные тесты' , link : '/ru/docs/inline-tests' } ,
106108 ] ,
107109 } ,
Original file line number Diff line number Diff line change 1+ # Test Attribute
2+
3+ The ` #[Test] ` attribute explicitly marks a method, function, or class as a test.
4+
5+ Can be placed on:
6+
7+ - ** Class** — all public methods become tests
8+ - ** Method** — only that method is a test
9+ - ** Function** — the function is a test
10+
11+ ``` php
12+ #[Test]
13+ final class OrderTest
14+ {
15+ public function createsOrder(): void { /* ... */ }
16+
17+ public function calculatesTotal(): void { /* ... */ }
18+
19+ public function appliesDiscount(): void { /* ... */ }
20+ }
21+
22+ final class UserTest
23+ {
24+ #[Test]
25+ public function validatesEmail(): void { /* ... */ }
26+
27+ #[Test]
28+ public function checksPermissions(): void { /* ... */ }
29+ }
30+
31+ #[Test]
32+ function checks_environment(): void { /* ... */ }
33+ ```
34+
35+ ## When to Use
36+
37+ Use ` #[Test] ` when:
38+
39+ - You want ** explicit** test declaration without relying on naming patterns
40+ - Your method/function name doesn't follow the ` test ` prefix convention
41+ - You prefer attribute-based discovery over convention-based
42+
43+ The attribute can be combined with [ naming conventions] ( ./naming-conventions ) in the same project.
Original file line number Diff line number Diff line change 1+ # Атрибут Test
2+
3+ Атрибут ` #[Test] ` явно помечает метод, функцию или класс как тест.
4+
5+ Можно ставить на:
6+
7+ - ** Класс** — все публичные методы становятся тестами
8+ - ** Метод** — только этот метод является тестом
9+ - ** Функцию** — функция является тестом
10+
11+ ``` php
12+ #[Test]
13+ final class OrderTest
14+ {
15+ public function createsOrder(): void { /* ... */ }
16+
17+ public function calculatesTotal(): void { /* ... */ }
18+
19+ public function appliesDiscount(): void { /* ... */ }
20+ }
21+
22+ final class UserTest
23+ {
24+ #[Test]
25+ public function validatesEmail(): void { /* ... */ }
26+
27+ #[Test]
28+ public function checksPermissions(): void { /* ... */ }
29+ }
30+
31+ #[Test]
32+ function checks_environment(): void { /* ... */ }
33+ ```
34+
35+ ## Когда использовать
36+
37+ Используйте ` #[Test] ` , когда:
38+
39+ - Хотите ** явно** объявлять тесты без привязки к именам
40+ - Имя метода/функции не следует конвенции с префиксом ` test `
41+ - Предпочитаете обнаружение по атрибутам, а не по конвенциям
42+
43+ Атрибут можно комбинировать с [ конвенциями именования] ( ./naming-conventions ) в одном проекте.
You can’t perform that action at this time.
0 commit comments