diff --git a/application/symfony/src/Attribut/SlugAttribut.php b/application/symfony/src/Attribut/SlugAttribut.php index 40e658b..a17e839 100644 --- a/application/symfony/src/Attribut/SlugAttribut.php +++ b/application/symfony/src/Attribut/SlugAttribut.php @@ -2,6 +2,8 @@ namespace App\Attribut; +use App\Exception\UnvalidValueException; + /** * @author kevinfrantz */ @@ -12,16 +14,30 @@ trait SlugAttribut */ protected $slug; + /** + * @param string $slug + * + * @throws UnvalidValueException + */ public function setSlug(string $slug): void { + if (is_numeric($slug)) { + throw new UnvalidValueException('A slug must not be numeric!'); + } $this->slug = $slug; } + /** + * @return string + */ public function getSlug(): string { return $this->slug; } + /** + * @return bool + */ public function hasSlug(): bool { return isset($this->slug); diff --git a/application/symfony/src/Exception/UnvalidValueException.php b/application/symfony/src/Exception/UnvalidValueException.php new file mode 100644 index 0000000..91ce284 --- /dev/null +++ b/application/symfony/src/Exception/UnvalidValueException.php @@ -0,0 +1,10 @@ +assertNull($this->slugAttribut->setSlug('')); $this->assertTrue($this->slugAttribut->hasSlug()); } + + public function testNumericSetException(): void + { + $this->expectException(UnvalidValueException::class); + $this->slugAttribut->setSlug('1234'); + } }