. */ namespace App\Tests\Services; use App\Entity\Parameters\CategoryParameter; use App\Entity\Parts\Category; use App\Exceptions\EntityNotSupportedException; use App\Services\ElementTypes; use PHPUnit\Framework\TestCase; class ElementTypesTest extends TestCase { public function testFromClass(): void { $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromClass(Category::class)); $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromClass(new Category())); //Should also work with subclasses $this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromClass(CategoryParameter::class)); $this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromClass(new CategoryParameter())); } public function testFromClassNotExisting(): void { $this->expectException(EntityNotSupportedException::class); ElementTypes::fromClass(\LogicException::class); } public function testFromValue(): void { //By enum value $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue('category')); $this->assertSame(ElementTypes::ATTACHMENT, ElementTypes::fromValue('attachment')); //From enum instance $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(ElementTypes::CATEGORY)); //From class string $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(Category::class)); $this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromValue(CategoryParameter::class)); //From class instance $this->assertSame(ElementTypes::CATEGORY, ElementTypes::fromValue(new Category())); $this->assertSame(ElementTypes::PARAMETER, ElementTypes::fromValue(new CategoryParameter())); } public function testGetDefaultLabelKey(): void { $this->assertSame('category.label', ElementTypes::CATEGORY->getDefaultLabelKey()); $this->assertSame('attachment.label', ElementTypes::ATTACHMENT->getDefaultLabelKey()); } public function testGetDefaultPluralLabelKey(): void { $this->assertSame('category.labelp', ElementTypes::CATEGORY->getDefaultPluralLabelKey()); $this->assertSame('attachment.labelp', ElementTypes::ATTACHMENT->getDefaultPluralLabelKey()); } }