ProductAttributeCombinationsUnitTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Tests\Unit\ProductAttributeCombinations;
  3. use App\Shop\Attributes\Attribute;
  4. use App\Shop\AttributeValues\AttributeValue;
  5. use App\Shop\AttributeValues\Repositories\AttributeValueRepository;
  6. use App\Shop\ProductAttributes\ProductAttribute;
  7. use App\Shop\Products\Product;
  8. use App\Shop\Products\Repositories\ProductRepository;
  9. use Tests\TestCase;
  10. class ProductAttributeCombinationsUnitTest extends TestCase
  11. {
  12. /** @test */
  13. public function it_can_create_a_product_attribute_combinations()
  14. {
  15. /**
  16. * Create:
  17. * - Attribute: Sizes
  18. * - Attribute value: small
  19. * - Attribute: Colors
  20. * - Attribute value: red
  21. */
  22. $attributeValue1 = new AttributeValue(['value' => 'small']);
  23. $attributeValueRepo1 = new AttributeValueRepository($attributeValue1);
  24. $attribute1 = factory(Attribute::class)->create(['name' => 'Sizes']);
  25. $createdValue1 = $attributeValueRepo1->associateToAttribute($attribute1);
  26. $attributeValue2 = new AttributeValue(['value' => 'red']);
  27. $attributeValueRepo2 = new AttributeValueRepository($attributeValue2);
  28. $attribute2 = factory(Attribute::class)->create(['name' => 'Colors']);
  29. $createdValue2 = $attributeValueRepo2->associateToAttribute($attribute2);
  30. $data = [
  31. 'quantity' => 2,
  32. 'price' => 2.50
  33. ];
  34. $productAttribute = new ProductAttribute($data);
  35. $product = factory(Product::class)->create();
  36. $productRepo = new ProductRepository($product);
  37. $created = $productRepo->saveProductAttributes($productAttribute);
  38. $combinations = $productRepo->saveCombination($created, $createdValue1, $createdValue2);
  39. $this->assertCount(2, $combinations);
  40. }
  41. }