Some checks are pending
CI / test (push) Waiting to run
Consistent brace style, spacing, and method expansion throughout domain, infrastructure, and test files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Domain\Article;
|
|
|
|
use App\Domain\Article\AttributeDefinition;
|
|
use App\Domain\Article\AttributeType;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class AttributeDefinitionTest extends TestCase
|
|
{
|
|
public function testConstructorSetsNameAndType(): void
|
|
{
|
|
$def = new AttributeDefinition('RAM', AttributeType::Select);
|
|
|
|
self::assertSame('RAM', $def->getName());
|
|
self::assertSame(AttributeType::Select, $def->getType());
|
|
self::assertNull($def->getUnit());
|
|
self::assertNull($def->getOptions());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider allAttributeTypes
|
|
*/
|
|
public function testSetTypeMutatesType(AttributeType $type): void
|
|
{
|
|
$def = new AttributeDefinition('Field', AttributeType::String);
|
|
$def->setType($type);
|
|
|
|
self::assertSame($type, $def->getType());
|
|
}
|
|
|
|
/** @return array<string, array{AttributeType}> */
|
|
public static function allAttributeTypes(): array
|
|
{
|
|
return array_combine(
|
|
array_map(static fn (AttributeType $t) => $t->value, AttributeType::cases()),
|
|
array_map(static fn (AttributeType $t) => [$t], AttributeType::cases()),
|
|
);
|
|
}
|
|
|
|
public function testSetNameAndUnit(): void
|
|
{
|
|
$def = new AttributeDefinition('Weight', AttributeType::Float);
|
|
$def->setName('Mass');
|
|
$def->setUnit('kg');
|
|
|
|
self::assertSame('Mass', $def->getName());
|
|
self::assertSame('kg', $def->getUnit());
|
|
}
|
|
|
|
public function testSetOptions(): void
|
|
{
|
|
$def = new AttributeDefinition('Grade', AttributeType::Select);
|
|
$def->setOptions(['A', 'B', 'C']);
|
|
|
|
self::assertSame(['A', 'B', 'C'], $def->getOptions());
|
|
}
|
|
|
|
public function testToStringReturnsName(): void
|
|
{
|
|
$def = new AttributeDefinition('CPU', AttributeType::String);
|
|
|
|
self::assertSame('CPU', (string) $def);
|
|
}
|
|
}
|