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

View File

@@ -109,6 +109,12 @@ class CustomerTest extends TestCase
self::assertInstanceOf(Customer::class, $sut->setVatId('ID 1234567890')); self::assertInstanceOf(Customer::class, $sut->setVatId('ID 1234567890'));
self::assertEquals('ID 1234567890', $sut->getVatId()); 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() public function testMetaFields()