From bef999767ee7b5fec1565144afd11a1a148ff197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vernet?= Date: Mon, 9 Sep 2024 14:32:13 +0200 Subject: [PATCH] fix: fix 500 when submitting step1 form without entering values (#684) --- src/Entity/Address.php | 26 +++++++++---------- .../Controller/User/AddressControllerTest.php | 17 ++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Entity/Address.php b/src/Entity/Address.php index 262aebe..cb7d480 100644 --- a/src/Entity/Address.php +++ b/src/Entity/Address.php @@ -45,7 +45,7 @@ class Address implements \Stringable #[ORM\Column(type: Types::STRING, length: 255, nullable: false)] #[Assert\NotBlank] #[Assert\Length(max: 255)] - private string $address; + private ?string $address = null; /** * Additional information for the address, eg: APT 555. @@ -90,7 +90,7 @@ class Address implements \Stringable #[ORM\Column(type: Types::STRING, length: 255, nullable: false)] #[Assert\NotBlank] #[Assert\Length(max: 255)] - private string $locality = ''; + private ?string $locality = ''; /** * Postal code, eg: "59160". @@ -98,7 +98,7 @@ class Address implements \Stringable #[ORM\Column(type: Types::STRING, length: 10, nullable: false)] #[Assert\NotBlank] #[Assert\Length(max: 20)] - private string $postalCode; + private ?string $postalCode = null; /** * ISO code of the country, eg: "FR". @@ -108,7 +108,7 @@ class Address implements \Stringable #[ORM\Column(type: Types::STRING, length: 2, nullable: false)] #[Assert\NotBlank] #[Assert\Country] - private string $country; + private ?string $country = null; /** * Latitude of the address (north/south), eg: "50.6322562". @@ -167,12 +167,12 @@ class Address implements \Stringable return $this; } - public function getAddress(): string + public function getAddress(): ?string { return $this->address; } - public function setAddress(string $address): self + public function setAddress(?string $address): self { $this->address = $address; @@ -227,7 +227,7 @@ class Address implements \Stringable return $this; } - public function getLocality(): string + public function getLocality(): ?string { return $this->locality; } @@ -237,7 +237,7 @@ class Address implements \Stringable return $this->locality !== ''; } - public function setLocality(string $locality): self + public function setLocality(?string $locality): self { $this->locality = $locality; @@ -256,24 +256,24 @@ class Address implements \Stringable return $this; } - public function getPostalCode(): string + public function getPostalCode(): ?string { return $this->postalCode; } - public function setPostalCode(string $postalCode): self + public function setPostalCode(?string $postalCode): self { $this->postalCode = $postalCode; return $this; } - public function getCountry(): string + public function getCountry(): ?string { return $this->country; } - public function setCountry(string $country): self + public function setCountry(?string $country): self { $this->country = $country; @@ -378,7 +378,7 @@ class Address implements \Stringable return $this; } - public function getSubAndLocality(): string + public function getSubAndLocality(): ?string { if (u($this->subLocality)->isEmpty()) { return $this->locality; diff --git a/tests/Functional/Controller/User/AddressControllerTest.php b/tests/Functional/Controller/User/AddressControllerTest.php index 983b6da..6c9fda7 100644 --- a/tests/Functional/Controller/User/AddressControllerTest.php +++ b/tests/Functional/Controller/User/AddressControllerTest.php @@ -143,6 +143,23 @@ final class AddressControllerTest extends WebTestCase self::assertSelectorTextContains('body', 'address.step1_action.no_address.warning'); } + /** + * Step1 form submitted without entering data. + */ + public function testStep1FormNothingFilledFailure(): void + { + $client = self::createClient(); + $this->loginAsUser16($client); + + $crawler = $client->request('GET', self::ROUTE_STEP1); + self::assertResponseIsSuccessful(); + + $form = $crawler->selectButton(self::STEP1_FORM_ID.'_submit')->form(); + $client->submit($form); + self::assertResponseIsUnprocessable(); + self::assertSelectorTextContains('body', 'This value should not be blank'); + } + /** * Step2 direct access is forbidden. */