Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve customer validation #2083

Merged
merged 1 commit into from Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Entity/Customer.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -428,7 +430,7 @@ public function getAddress(): ?string
return $this->address;
}

public function setCountry(string $country): Customer
public function setCountry(?string $country): Customer
{
$this->country = $country;

Expand All @@ -440,14 +442,14 @@ public function getCountry(): ?string
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;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Entity/CustomerTest.php
Expand Up @@ -109,6 +109,12 @@ public function testSetterAndGetter()

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()
Expand Down