SuperSeller3000/tests/Unit/Application/Article/ArticleValidatorTest.php
Simon Kuehn 6bf001b0c0 feat: implement Plan 2 — Article Management API
- 6 new domain repository interfaces (StoragePath, ArticlePhoto, AttributeValue, ChannelField, ArticleTypePlatformConfig, AttributeMapping)
- 6 Doctrine repository implementations
- StorageManager with multi-path quota-aware file storage (LocalStorageManager)
- Application services: ArticleTypeService, ArticleService, ArticleValidator, PhotoService, PlatformService, MappingService
- REST controllers: ArticleType, Article, Photo, Platform, Mapping (all under /api prefix)
- inventory_number sequence migration
- 22 unit tests passing, PHPStan level 9 clean, CS Fixer clean
- Fixed phpdoc_to_comment CS Fixer rule (disabled) to preserve @var type annotations
- Fixed PHPStan: User::getUserIdentifier non-empty-string, AIPipelineJob nullable missingFields

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 05:19:20 +00:00

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 test_valid_when_all_attributes_set(): 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 test_returns_missing_attribute_names(): 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 test_all_missing_when_no_values_set(): void
{
$article = new Article($this->type, 'NB-001', 'INV-001', 1, ArticleCondition::Good);
$missing = $this->validator->getMissingAttributes($article);
$this->assertCount(2, $missing);
}
}