mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented ClassAttribut
This commit is contained in:
		
							
								
								
									
										39
									
								
								application/symfony/src/Attribut/ClassAttribut.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								application/symfony/src/Attribut/ClassAttribut.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Attribut; | ||||
|  | ||||
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||||
|  | ||||
| /** | ||||
|  * @see ClassAttributInterface | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| trait ClassAttribut | ||||
| { | ||||
|     /** | ||||
|      * @var string | ||||
|      */ | ||||
|     private $class; | ||||
|  | ||||
|     /** | ||||
|      * @param string $class | ||||
|      */ | ||||
|     public function setClass(string $class): void | ||||
|     { | ||||
|         if (class_exists($class)) { | ||||
|             $this->class = $class; | ||||
|  | ||||
|             return; | ||||
|         } | ||||
|         throw new NotFoundHttpException('Class '.$class.' couldn\'t be found!'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getClass(): string | ||||
|     { | ||||
|         return $this->class; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								application/symfony/src/Attribut/ClassAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								application/symfony/src/Attribut/ClassAttributInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Attribut; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface ClassAttributInterface | ||||
| { | ||||
|     /** | ||||
|      * @param string $class | ||||
|      */ | ||||
|     public function setClass(string $class): void; | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getClass(): string; | ||||
| } | ||||
| @@ -0,0 +1,44 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Attribut; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Attribut\ClassAttributInterface; | ||||
| use App\Attribut\ClassAttribut; | ||||
| use App\Entity\Source\AbstractSource; | ||||
| use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||||
|  | ||||
| class ClassAttributTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @var ClassAttributInterface | ||||
|      */ | ||||
|     protected $classAttribut; | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         $this->classAttribut = new class() implements ClassAttributInterface { | ||||
|             use ClassAttribut; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     public function testConstructor(): void | ||||
|     { | ||||
|         $this->expectException(\TypeError::class); | ||||
|         $this->classAttribut->getClass(); | ||||
|     } | ||||
|  | ||||
|     public function testAccessors(): void | ||||
|     { | ||||
|         $class = AbstractSource::class; | ||||
|         $this->assertNull($this->classAttribut->setClass($class)); | ||||
|         $this->assertEquals($class, $this->classAttribut->getClass()); | ||||
|     } | ||||
|  | ||||
|     public function testException(): void | ||||
|     { | ||||
|         $class = 'NOTEXISTINGCLASS'; | ||||
|         $this->expectException(NotFoundHttpException::class); | ||||
|         $this->classAttribut->setClass($class); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user