fix(commercial) : billingEmail vide rejete en 422 et non en 500 (RG-1.11)
Pull Request — Quality gate / Backend (PHP CS + PHPUnit) (pull_request) Successful in 1m55s
Pull Request — Quality gate / Frontend (lint + Vitest + build) (pull_request) Successful in 1m18s

Le callback validateBillingEmailPresence testait null === billingEmail. Une
chaine vide "" (champ vide envoye par le client) passait donc les validators ;
le ClientAddressProcessor la normalisait ensuite en null APRES la validation,
puis la persistance d'une adresse is_billing=true avec billing_email=null
violait le CHECK chk_client_address_billing_email -> 500 DBAL au lieu du 422
attendu. Symetriquement, "" sur une adresse non facturable etait rejete a tort
en 422 alors qu'un champ vide equivaut a une absence d'email.

Le callback raisonne desormais sur la presence effective (null OU chaine vide
apres trim = absent), coheremment avec la normalisation du processor. Deux cas
de test ajoutes : adresse facturable + "" -> 422, adresse non facturable +
"" -> 201.
This commit is contained in:
Matthieu
2026-06-02 00:10:43 +02:00
parent 039d4c6391
commit e6188535fd
2 changed files with 66 additions and 2 deletions
@@ -202,18 +202,28 @@ class ClientAddress implements TimestampableInterface, BlamableInterface
* RG-1.11 : l'email de facturation est obligatoire si l'adresse est de
* facturation, et interdit sinon. Mirror applicatif (422) du CHECK
* chk_client_address_billing_email.
*
* On raisonne sur la PRESENCE effective de l'email : null ET chaine vide
* sont traites comme « absent », car le ClientAddressProcessor normalise une
* chaine vide en null APRES la validation (RG-1.21). Sans ce traitement,
* billingEmail="" passerait les callbacks (null === "" est faux) puis serait
* persiste en null avec is_billing=true -> violation du CHECK -> 500 au lieu
* du 422 attendu (et symetriquement, "" sur une adresse non facturable
* serait rejete a tort).
*/
#[Assert\Callback]
public function validateBillingEmailPresence(ExecutionContextInterface $context): void
{
if ($this->isBilling && null === $this->billingEmail) {
$hasBillingEmail = null !== $this->billingEmail && '' !== trim($this->billingEmail);
if ($this->isBilling && !$hasBillingEmail) {
$context->buildViolation('L\'email de facturation est obligatoire pour une adresse de facturation.')
->atPath('billingEmail')
->addViolation()
;
}
if (!$this->isBilling && null !== $this->billingEmail) {
if (!$this->isBilling && $hasBillingEmail) {
$context->buildViolation('L\'email de facturation n\'est autorisé que sur une adresse de facturation.')
->atPath('billingEmail')
->addViolation()