|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\Functional\Budget; |
| 6 | + |
| 7 | +use App\Tests\Common\Factory\BudgetFactory; |
| 8 | +use App\Tests\Common\Factory\UserFactory; |
| 9 | +use App\Tests\Functional\TestBase; |
| 10 | +use PHPUnit\Framework\Attributes\Group; |
| 11 | +use PHPUnit\Framework\Attributes\Test; |
| 12 | +use PHPUnit\Framework\Attributes\TestDox; |
| 13 | +use Symfony\Component\HttpFoundation\Request; |
| 14 | + |
| 15 | +/** |
| 16 | + * @internal |
| 17 | + */ |
| 18 | +#[Group('integration')] |
| 19 | +#[Group('controller')] |
| 20 | +#[Group('budget')] |
| 21 | +#[Group('budget-controller')] |
| 22 | +final class UpdateBudgetControllerTest extends TestBase |
| 23 | +{ |
| 24 | + private const string API_ENDPOINT = '/api/budgets'; |
| 25 | + |
| 26 | + #[TestDox('When you call PUT /api/budgets, it should update and return the budget')] |
| 27 | + #[Test] |
| 28 | + public function updateBudgetController_WhenDataOk_ReturnsBudget(): void |
| 29 | + { |
| 30 | + // ARRANGE |
| 31 | + $user = UserFactory::createOne()->_real(); |
| 32 | + $budget = BudgetFactory::createOne([ |
| 33 | + 'user' => $user, |
| 34 | + ])->_real(); |
| 35 | + |
| 36 | + $this->client->loginUser($user); |
| 37 | + |
| 38 | + $budgetPayload = [ |
| 39 | + 'date' => '2024-02', |
| 40 | + 'incomes' => [ |
| 41 | + [ |
| 42 | + 'name' => 'Salaire', |
| 43 | + 'amount' => 2500, |
| 44 | + ], |
| 45 | + [ |
| 46 | + 'name' => 'Prime', |
| 47 | + 'amount' => 500, |
| 48 | + ], |
| 49 | + ], |
| 50 | + 'expenses' => [ |
| 51 | + [ |
| 52 | + 'name' => 'Loyer', |
| 53 | + 'amount' => 1000, |
| 54 | + 'category' => 'Logement', |
| 55 | + ], |
| 56 | + [ |
| 57 | + 'name' => 'Electricité', |
| 58 | + 'amount' => 100, |
| 59 | + 'category' => 'Logement', |
| 60 | + ], |
| 61 | + [ |
| 62 | + 'name' => 'Courses', |
| 63 | + 'amount' => 200, |
| 64 | + 'category' => 'Alimentation', |
| 65 | + ], |
| 66 | + [ |
| 67 | + 'name' => 'Téléphone', |
| 68 | + 'amount' => 20, |
| 69 | + 'category' => 'Abonnements', |
| 70 | + ], |
| 71 | + ], |
| 72 | + ]; |
| 73 | + |
| 74 | + // ACT |
| 75 | + $response = $this->clientRequest( |
| 76 | + Request::METHOD_PUT, |
| 77 | + self::API_ENDPOINT . '/' . $budget->getId(), |
| 78 | + $budgetPayload |
| 79 | + ); |
| 80 | + $responseData = $response['data'] ?? []; |
| 81 | + |
| 82 | + // ASSERT |
| 83 | + self::assertResponseIsSuccessful(); |
| 84 | + self::assertResponseFormatSame('json'); |
| 85 | + self::assertSame('Budget 2024-02', $responseData['name']); |
| 86 | + self::assertSame(1680, $responseData['savingCapacity']); |
| 87 | + } |
| 88 | +} |
0 commit comments