@@ -39,6 +39,106 @@ features:
3939 details : Раздельные фасады Assert (сейчас) и Expect (потом) с пайповыми ассертами для типобезопасных проверок.
4040---
4141
42+ <script setup >
43+ const assertTabs = [
44+ { name: ' Assert.php' , slot: ' assert' , icon: ' testo' },
45+ { name: ' Expect.php' , slot: ' expect' , icon: ' testo' },
46+ { name: ' Exception.php' , slot: ' expectException' , icon: ' testo' },
47+ { name: ' Attributes.php' , slot: ' expectAttr' , icon: ' testo-class' },
48+ ]
49+ </script >
50+
51+ <div class =" home-feature " >
52+
53+ ## Продуманный API ассертов
54+
55+ <div class =" home-feature-row " >
56+ <div class =" home-feature-text " >
57+
58+ Функции проверок разбиты на семантические группы:
59+
60+ - Фасад ` Assert:: ` — утверждения, выполняются сразу
61+ - Фасад ` Expect:: ` — ожидания, откладываются до завершения теста
62+
63+ Пайповый синтаксис с группировкой по типу делает код лаконичным и типобезопасным.
64+
65+ </div >
66+ <div class =" home-feature-code " >
67+ <CodeTabs :tabs =" assertTabs " >
68+
69+ <template #assert>
70+
71+ ``` php
72+ use Testo\Assert;
73+
74+ // Пайповые ассерты — группировка по типу
75+ Assert::string($email)->contains('@');
76+ Assert::int($age)->greaterThan(18);
77+ Assert::file('config.php')->exists();
78+
79+ Assert::array($order->items)
80+ ->allOf(Item::class)
81+ ->hasCount(3);
82+ ```
83+
84+ </template >
85+
86+ <template #expect>
87+
88+ ``` php
89+ use Testo\Expect;
90+
91+ // ORM должен остаться в памяти
92+ Expect::leaks($orm);
93+
94+ // Тест упадёт, если сущности не будут подчищены
95+ Expect::notLeaks(...$entitis);
96+
97+ // Валидация вывода
98+ Expect::output()->contains('Done');
99+ ```
100+
101+ </template >
102+
103+ <template #expectException>
104+
105+ ``` php
106+ // Где вы ещё такое видели?
107+ Expect::exception(ValidationException::class)
108+ ->fromMethod(Service::class, 'validateInput')
109+ ->withMessage('Invalid input')
110+ ->withPrevious(
111+ WrongTypeException::class,
112+ static fn (ExpectedException $e) => $e
113+ ->withCode(42)
114+ ->withMessage('Field "age" must be integer.'),
115+ );
116+ ```
117+
118+ </template >
119+
120+ <template #expectAttr>
121+
122+ ``` php
123+ /**
124+ * Можно использовать атрибуты для ожидания исключений
125+ */
126+ #[ExpectException(ValidationException::class)]
127+ public function testInvalidInput(): void
128+ {
129+ $input = ['age' => 'twenty'];
130+
131+ $this->service->validateInput($input);
132+ }
133+ ```
134+
135+ </template >
136+
137+ </CodeTabs >
138+ </div >
139+ </div >
140+ </div >
141+
42142<div class =" sponsors-section " >
43143 <h2 class =" sponsors-title " >Спонсоры</h2 >
44144 <div class =" sponsors-grid " >
0 commit comments