PHPUnit config (phpunit.dist.xml, bin/phpunit, bootstrap.php), PHP CS Fixer config, .editorconfig. Separate .env.dev/.env.test templates. Ollama tunnel setup script. Architecture and plan docs. Updated application-layer unit tests to match current service signatures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Application\Article;
|
|
|
|
use App\Application\Article\ArticleValidator;
|
|
use App\Domain\Article\Article;
|
|
use App\Domain\Article\ArticleCondition;
|
|
use App\Domain\Article\ArticleType;
|
|
use App\Domain\Article\AttributeDefinition;
|
|
use App\Domain\Article\AttributeType;
|
|
use App\Domain\Article\AttributeValue;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class ArticleValidatorTest extends TestCase
|
|
{
|
|
private ArticleValidator $validator;
|
|
private ArticleType $type;
|
|
private AttributeDefinition $ramDef;
|
|
private AttributeDefinition $cpuDef;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->validator = new ArticleValidator();
|
|
$this->type = new ArticleType('Notebook');
|
|
$this->ramDef = new AttributeDefinition('RAM', AttributeType::String);
|
|
$this->cpuDef = new AttributeDefinition('CPU', AttributeType::String);
|
|
$this->type->addAttributeDefinition($this->ramDef);
|
|
$this->type->addAttributeDefinition($this->cpuDef);
|
|
}
|
|
|
|
public function testValidWhenAllAttributesSet(): void
|
|
{
|
|
$article = new Article($this->type, 'NB-001', 'INV-001', 1, ArticleCondition::Good);
|
|
$article->setAttributeValue(new AttributeValue($article, $this->ramDef, '16 GB'));
|
|
$article->setAttributeValue(new AttributeValue($article, $this->cpuDef, 'Intel i7'));
|
|
|
|
$missing = $this->validator->getMissingAttributes($article);
|
|
|
|
$this->assertEmpty($missing);
|
|
$this->assertTrue($this->validator->isValid($article));
|
|
}
|
|
|
|
public function testReturnsMissingAttributeNames(): void
|
|
{
|
|
$article = new Article($this->type, 'NB-001', 'INV-001', 1, ArticleCondition::Good);
|
|
$article->setAttributeValue(new AttributeValue($article, $this->ramDef, '16 GB'));
|
|
// cpuDef not set
|
|
|
|
$missing = $this->validator->getMissingAttributes($article);
|
|
|
|
$this->assertCount(1, $missing);
|
|
$this->assertContains('CPU', $missing);
|
|
$this->assertFalse($this->validator->isValid($article));
|
|
}
|
|
|
|
public function testAllMissingWhenNoValuesSet(): void
|
|
{
|
|
$article = new Article($this->type, 'NB-001', 'INV-001', 1, ArticleCondition::Good);
|
|
|
|
$missing = $this->validator->getMissingAttributes($article);
|
|
|
|
$this->assertCount(2, $missing);
|
|
}
|
|
}
|