-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathAbstractWebTestCase.php
More file actions
96 lines (80 loc) · 2.8 KB
/
Copy pathAbstractWebTestCase.php
File metadata and controls
96 lines (80 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* Copyright (c) 2025-2026 Netresearch DTT GmbH
* SPDX-License-Identifier: AGPL-3.0-only
*/
declare(strict_types=1);
namespace Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
use Tests\Traits\AuthenticationTestTrait;
use Tests\Traits\DatabaseTestTrait;
use Tests\Traits\HttpClientTrait;
use Tests\Traits\JsonAssertionsTrait;
use Tests\Traits\TestDataTrait;
/**
* Abstract base test case that combines all test functionality.
*
* This class serves as a facade that uses focused traits for different responsibilities:
* - DatabaseTestTrait: Transaction isolation, database reset, query builder setup
* - AuthenticationTestTrait: User login, session management, authentication helpers
* - JsonAssertionsTrait: JSON response validation, API testing helpers
* - TestDataTrait: Fixture loading, test data management
* - HttpClientTrait: Client setup, HTTP request helpers
*
* Maintains backward compatibility while providing better separation of concerns.
*/
abstract class AbstractWebTestCase extends SymfonyWebTestCase
{
use AuthenticationTestTrait;
use DatabaseTestTrait;
use HttpClientTrait;
use JsonAssertionsTrait;
use TestDataTrait;
protected static function ensureKernelShutdown(): void
{
$wasBooted = static::$booted;
parent::ensureKernelShutdown();
if ($wasBooted) {
@restore_exception_handler();
}
}
/**
* Set up before each test.
* Coordinates initialization across all traits.
*/
protected function setUp(): void
{
parent::setUp();
// Initialize HTTP client (from HttpClientTrait)
$this->initializeHttpClient();
// Initialize database and transactions (from DatabaseTestTrait)
$this->initializeDatabase();
// Authenticate user in session (from AuthenticationTestTrait)
$this->logInSession();
// Avoid repeatedly setting translator/request locale to reduce overhead
// Keep defaults from framework config; individual tests can override if needed
}
/**
* Tear down after each test.
* Coordinates cleanup across all traits.
*/
protected function tearDown(): void
{
// Clean up database (from DatabaseTestTrait)
$this->cleanupDatabase();
parent::tearDown();
}
/**
* Clear static state between test runs (important for parallel testing).
* This helps ensure isolated test environments for parallel runs.
* Coordinates cleanup across all traits.
*/
public static function tearDownAfterClass(): void
{
// Clear database state (from DatabaseTestTrait)
self::clearDatabaseState();
// Clear test data state (from TestDataTrait)
self::clearTestDataState();
parent::tearDownAfterClass();
}
}