ver. 0.302: REST API product variants, attributes dictionary, attribute filtering
- Add variant CRUD endpoints (variants, create_variant, update_variant, delete_variant) - Add dictionaries/attributes endpoint with multilingual names and values - Add attribute_* filter params for product list filtering by attribute values - Enrich product detail attributes with translated names (attribute_names, value_names) - Include variants array in product detail response for parent products - Add price_brutto validation on product create - Batch-load attribute/value translations (4 queries instead of N+1) - Add 43 new unit tests (730 total, 2066 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ namespace Tests\Unit\api\Controllers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use api\Controllers\DictionariesApiController;
|
||||
use Domain\Attribute\AttributeRepository;
|
||||
use Domain\ShopStatus\ShopStatusRepository;
|
||||
use Domain\Transport\TransportRepository;
|
||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||
@@ -12,6 +13,7 @@ class DictionariesApiControllerTest extends TestCase
|
||||
private $mockStatusRepo;
|
||||
private $mockTransportRepo;
|
||||
private $mockPaymentRepo;
|
||||
private $mockAttrRepo;
|
||||
private $controller;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -19,11 +21,13 @@ class DictionariesApiControllerTest extends TestCase
|
||||
$this->mockStatusRepo = $this->createMock(ShopStatusRepository::class);
|
||||
$this->mockTransportRepo = $this->createMock(TransportRepository::class);
|
||||
$this->mockPaymentRepo = $this->createMock(PaymentMethodRepository::class);
|
||||
$this->mockAttrRepo = $this->createMock(AttributeRepository::class);
|
||||
|
||||
$this->controller = new DictionariesApiController(
|
||||
$this->mockStatusRepo,
|
||||
$this->mockTransportRepo,
|
||||
$this->mockPaymentRepo
|
||||
$this->mockPaymentRepo,
|
||||
$this->mockAttrRepo
|
||||
);
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
@@ -136,4 +140,50 @@ class DictionariesApiControllerTest extends TestCase
|
||||
|
||||
$this->assertSame(405, http_response_code());
|
||||
}
|
||||
|
||||
// --- attributes ---
|
||||
|
||||
public function testAttributesReturnsFormattedList(): void
|
||||
{
|
||||
$this->mockAttrRepo->method('listForApi')
|
||||
->willReturn([
|
||||
[
|
||||
'id' => 5,
|
||||
'type' => 0,
|
||||
'status' => 1,
|
||||
'names' => ['pl' => 'Rozmiar', 'en' => 'Size'],
|
||||
'values' => [
|
||||
[
|
||||
'id' => 12,
|
||||
'names' => ['pl' => 'M', 'en' => 'M'],
|
||||
'is_default' => 1,
|
||||
'impact_on_the_price' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
ob_start();
|
||||
$this->controller->attributes();
|
||||
$output = ob_get_clean();
|
||||
|
||||
$json = json_decode($output, true);
|
||||
$this->assertSame('ok', $json['status']);
|
||||
$this->assertCount(1, $json['data']);
|
||||
$this->assertSame(5, $json['data'][0]['id']);
|
||||
$this->assertSame('Rozmiar', $json['data'][0]['names']['pl']);
|
||||
$this->assertCount(1, $json['data'][0]['values']);
|
||||
$this->assertSame(12, $json['data'][0]['values'][0]['id']);
|
||||
}
|
||||
|
||||
public function testAttributesRejectsPostMethod(): void
|
||||
{
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
|
||||
ob_start();
|
||||
$this->controller->attributes();
|
||||
$output = ob_get_clean();
|
||||
|
||||
$this->assertSame(405, http_response_code());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user