Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DeleteTestDataAction | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\SuperAdmin; |
| 6 | |
| 7 | use App\Domain\Auth\Data\UserAuthData; |
| 8 | use App\Domain\Exception\ForbiddenException; |
| 9 | use App\Domain\SuperAdmin\Service\SuperAdminService; |
| 10 | use App\Renderer\JsonRenderer; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | /** |
| 15 | * Delete all test data (users, investors, accounts, transactions with @testdata.local emails). |
| 16 | */ |
| 17 | final readonly class DeleteTestDataAction |
| 18 | { |
| 19 | public function __construct( |
| 20 | private JsonRenderer $renderer, |
| 21 | private SuperAdminService $service, |
| 22 | ) {} |
| 23 | |
| 24 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 25 | { |
| 26 | // Verify super_admin role |
| 27 | $user = $request->getAttribute('user'); |
| 28 | if (!$user instanceof UserAuthData || $user->role !== 'super_admin') { |
| 29 | throw new ForbiddenException('Super admin access required'); |
| 30 | } |
| 31 | |
| 32 | $deleted = $this->service->deleteTestData(); |
| 33 | |
| 34 | $total = $deleted['users'] + $deleted['investors'] + $deleted['accounts'] + $deleted['transactions']; |
| 35 | |
| 36 | return $this->renderer->json($response, [ |
| 37 | 'success' => true, |
| 38 | 'message' => "Deleted {$total} test data records", |
| 39 | 'data' => $deleted, |
| 40 | ]); |
| 41 | } |
| 42 | } |