mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 01:09:41 +00:00 
			
		
		
		
	Added numeric check for slug attribut
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
							
								
								
									
										10
									
								
								application/symfony/src/Exception/UnvalidValueException.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								application/symfony/src/Exception/UnvalidValueException.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Exception; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class UnvalidValueException extends \Exception | ||||
| { | ||||
| } | ||||
| @@ -5,6 +5,7 @@ namespace Tests\Attribut; | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Attribut\SlugAttributInterface; | ||||
| use App\Attribut\SlugAttribut; | ||||
| use App\Exception\UnvalidValueException; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
| @@ -39,4 +40,10 @@ class SlugAttributTest extends TestCase | ||||
|         $this->assertNull($this->slugAttribut->setSlug('')); | ||||
|         $this->assertTrue($this->slugAttribut->hasSlug()); | ||||
|     } | ||||
|  | ||||
|     public function testNumericSetException(): void | ||||
|     { | ||||
|         $this->expectException(UnvalidValueException::class); | ||||
|         $this->slugAttribut->setSlug('1234'); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user