Files
clinicpro/tests/Settlement/FinancialBreakdownIntegrityTest.php
T
hamedandClaude Opus 4.8 d14ac38da5 fix(db): RESTRICT delete of a Payment that has a FinancialBreakdown (H4)
The ledger FK used ON DELETE CASCADE on a non-nullable column, so deleting a
Payment silently destroyed its immutable financial breakdown rows. Switch to
RESTRICT — a settled payment can no longer be deleted out from under its ledger.

Regression: tests/Settlement/FinancialBreakdownIntegrityTest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 19:10:53 +03:30

38 lines
1.1 KiB
PHP

<?php
namespace App\Tests\Settlement;
use App\Payment\Entity\Payment;
use App\Settlement\Entity\FinancialBreakdown;
use App\Tests\ApiTestCase;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
/**
* A FinancialBreakdown is an immutable ledger row. Deleting the Payment it
* settles must be blocked (ON DELETE RESTRICT) rather than silently cascading
* the ledger row away.
*/
class FinancialBreakdownIntegrityTest extends ApiTestCase
{
public function testDeletingPaymentWithBreakdownIsRestricted(): void
{
$user = $this->createUser();
$payment = new Payment($user, 100_000, 'mellat', Payment::TYPE_APPOINTMENT);
$this->em->persist($payment);
$breakdown = new FinancialBreakdown(
$payment,
FinancialBreakdown::SOURCE_APPOINTMENT,
$user,
100_000, 0, '0.00', 0, 100_000, '10.00', 10_000, 90_000,
null, null, null,
);
$this->em->persist($breakdown);
$this->em->flush();
$this->em->remove($payment);
$this->expectException(ForeignKeyConstraintViolationException::class);
$this->em->flush();
}
}