Skip to content

Commit

Permalink
NFM-2 Add product facts from request factory
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Oct 6, 2024
1 parent a00546c commit 31ba26b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/DataTypeFactory/ProductFactsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Copyright © MB Arbatos Klubas. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace FreshAdvance\NutritionFacts\DataTypeFactory;

use FreshAdvance\NutritionFacts\Admin\Transput\EditRequestInterface;
use FreshAdvance\NutritionFacts\DataType\ProductFacts;
use FreshAdvance\NutritionFacts\DataType\ProductFactsInterface;

class ProductFactsFactory implements ProductFactsFactoryInterface
{
public function __construct(
protected EditRequestInterface $editRequest
) {
}

public function getFromRequest(): ProductFactsInterface
{
return new ProductFacts(
title: '',
nutritionFacts: $this->editRequest->getNutritionFacts(),
);
}
}
15 changes: 15 additions & 0 deletions src/DataTypeFactory/ProductFactsFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Copyright © MB Arbatos Klubas. All rights reserved.
* See LICENSE file for license details.
*/

namespace FreshAdvance\NutritionFacts\DataTypeFactory;

use FreshAdvance\NutritionFacts\DataType\ProductFactsInterface;

interface ProductFactsFactoryInterface
{
public function getFromRequest(): ProductFactsInterface;
}
5 changes: 4 additions & 1 deletion src/DataTypeFactory/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ services:
autowire: true

FreshAdvance\NutritionFacts\DataTypeFactory\NutritionFactsFactoryInterface:
class: FreshAdvance\NutritionFacts\DataTypeFactory\NutritionFactsFactory
class: FreshAdvance\NutritionFacts\DataTypeFactory\NutritionFactsFactory

FreshAdvance\NutritionFacts\DataTypeFactory\ProductFactsFactoryInterface:
class: FreshAdvance\NutritionFacts\DataTypeFactory\ProductFactsFactory
1 change: 1 addition & 0 deletions tests/Integration/ServiceAvailabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function serviceAvailabilityDataProvider(): array
{
return [
[\FreshAdvance\NutritionFacts\DataTypeFactory\NutritionFactsFactoryInterface::class],
[\FreshAdvance\NutritionFacts\DataTypeFactory\ProductFactsFactoryInterface::class],
[\FreshAdvance\NutritionFacts\Repository\FactsDataAccessInterface::class],
];
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/DataTypeFactory/ProductFactsFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Copyright © MB Arbatos Klubas. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace FreshAdvance\NutritionFacts\Tests\Unit\DataTypeFactory;

use FreshAdvance\NutritionFacts\Admin\Transput\EditRequestInterface;
use FreshAdvance\NutritionFacts\DataType\NutritionFactsInterface;
use FreshAdvance\NutritionFacts\DataTypeFactory\ProductFactsFactory;
use PHPUnit\Framework\TestCase;

class ProductFactsFactoryTest extends TestCase
{
public function testGetFromRequest(): void
{
$editRequestStub = $this->createConfiguredMock(EditRequestInterface::class, [
'getNutritionFacts' => $nutritionFacts = $this->createStub(NutritionFactsInterface::class),
]);

$sut = new ProductFactsFactory(
editRequest: $editRequestStub
);

$productFacts = $sut->getFromRequest();

$this->assertSame($nutritionFacts, $productFacts->getNutritionFacts());
}
}

0 comments on commit 31ba26b

Please sign in to comment.