improve customer validation (#2083)

This commit is contained in:
Kevin Papst
2020-11-02 00:50:26 +01:00
committed by GitHub
parent b012332d82
commit aba06ba3f0
2 changed files with 11 additions and 3 deletions

View File

@@ -152,6 +152,7 @@ class Customer implements EntityWithMetaFields
*
* @ORM\Column(name="country", type="string", length=2, nullable=false)
* @Assert\NotBlank()
* @Assert\Country()
* @Assert\Length(max=2)
*/
private $country;
@@ -165,6 +166,7 @@ class Customer implements EntityWithMetaFields
*
* @ORM\Column(name="currency", type="string", length=3, nullable=false)
* @Assert\NotBlank()
* @Assert\Currency()
* @Assert\Length(max=3)
*/
private $currency = self::DEFAULT_CURRENCY;
@@ -428,7 +430,7 @@ class Customer implements EntityWithMetaFields
return $this->address;
}
public function setCountry(string $country): Customer
public function setCountry(?string $country): Customer
{
$this->country = $country;
@@ -440,14 +442,14 @@ class Customer implements EntityWithMetaFields
return $this->country;
}
public function setCurrency(string $currency): Customer
public function setCurrency(?string $currency): Customer
{
$this->currency = $currency;
return $this;
}
public function getCurrency(): string
public function getCurrency(): ?string
{
return $this->currency;
}

View File

@@ -109,6 +109,12 @@ class CustomerTest extends TestCase
self::assertInstanceOf(Customer::class, $sut->setVatId('ID 1234567890'));
self::assertEquals('ID 1234567890', $sut->getVatId());
self::assertInstanceOf(Customer::class, $sut->setCountry(null));
self::assertNull($sut->getCountry());
self::assertInstanceOf(Customer::class, $sut->setCurrency(null));
self::assertNull($sut->getCurrency());
}
public function testMetaFields()