docs(articles): From Magento to Symfony, a requalification guide grouped into sections
uk/articles/magento-to-symfony/quality/testing.md
новий файл +47
−0
1
+
# Тести
2
+
3
+
**Magento** · інтеграційний тест контролера
4
+
5
+
```php
6
+
/**
7
+
* @magentoDataFixture Vendor_Faq::Test/_files/question.php
8
+
* @magentoAppArea frontend
9
+
*/
10
+
public function testView(): void
11
+
{
12
+
$this->dispatch('faq/question/view/id/1');
13
+
$this->assertStringContainsString(
14
+
'How to return',
15
+
$this->getResponse()->getBody()
16
+
);
17
+
}
18
+
```
19
+
20
+
**Symfony** · WebTestCase + Foundry
21
+
22
+
```php
23
+
final class FaqControllerTest extends WebTestCase
24
+
{
25
+
use Factories, ResetDatabase;
26
+
27
+
public function testShowsQuestion(): void
28
+
{
29
+
$client = static::createClient();
30
+
QuestionFactory::createOne([
31
+
'title' => 'How to return',
32
+
'slug' => 'how-to-return',
33
+
]);
34
+
35
+
$client->request('GET', '/faq/how-to-return');
36
+
37
+
self::assertResponseIsSuccessful();
38
+
self::assertSelectorTextContains('h1', 'How to return');
39
+
}
40
+
}
41
+
```
42
+
43
+
- **Unit:** звичайний `TestCase`, як і в Magento.
44
+
- **KernelTestCase:** справжній контейнер, `self::getContainer()->get(Importer::class)` дає навіть приватні сервіси, якщо їх десь використано.
45
+
- **WebTestCase:** HTTP-запити без вебсервера, асерти на відповідь і DOM.
46
+
- **БД:** окрема тестова база з `.env.test`, DAMA DoctrineTestBundle відкочує транзакцію після кожного тесту, Foundry створює дані фабриками замість файлів-фікстур.
47
+
- **Підміна сервісу:** `self::getContainer()->set(ErpClient::class, $mock)` до першого використання.