Skip to content

Commit

Permalink
Merge pull request #73 from CommerceWeavers/fix-build
Browse files Browse the repository at this point in the history
Fix for builds
  • Loading branch information
lchrusciel authored Oct 3, 2024
2 parents 239026d + 165e6b6 commit 516182b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Handler/CreateBoughtTogetherAssociationTypeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
final class CreateBoughtTogetherAssociationTypeHandler
{
/**
* @param FactoryInterface<ProductAssociationTypeInterface> $productAssociationTypeFactory
* @implements FactoryInterface<ProductAssociationTypeInterface> $productAssociationTypeFactory
*/
public function __construct(
private FactoryInterface $productAssociationTypeFactory,
private ProductAssociationTypeRepositoryInterface $productAssociationTypeRepository,
private readonly FactoryInterface $productAssociationTypeFactory,
private readonly ProductAssociationTypeRepositoryInterface $productAssociationTypeRepository,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __invoke(SynchronizeFrequentlyBoughtTogetherProducts $command):
$lastSynchronizationDate = $this->lastSynchronizationDateProvider->provide();

$synchronizationResult = $this->frequentlyBoughtTogetherProductsSynchronizer->synchronize(
$lastSynchronizationDate ?? (new \DateTimeImmutable())->setTimestamp(0)
$lastSynchronizationDate ?? (new \DateTimeImmutable())->setTimestamp(0),
);

$event = new SynchronizationEnded(
Expand Down
14 changes: 9 additions & 5 deletions src/Provider/BoughtTogetherProductsAssociationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@
use CommerceWeavers\SyliusAlsoBoughtPlugin\Exception\BoughtTogetherAssociationTypeNotFoundException;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductAssociation;
use Sylius\Component\Product\Model\ProductAssociationInterface;
use Sylius\Component\Product\Model\ProductAssociationType;
use Sylius\Component\Product\Model\ProductAssociationTypeInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;

final class BoughtTogetherProductsAssociationProvider implements BoughtTogetherProductsAssociationProviderInterface
{
/**
* @param FactoryInterface<ProductAssociation> $productAssociationFactory
* @param RepositoryInterface<ProductAssociationType> $productAssociationTypeRepository
* @implements FactoryInterface<ProductAssociation> $productAssociationFactory
* @implements RepositoryInterface<ProductAssociationType> $productAssociationTypeRepository
*/
public function __construct(
private FactoryInterface $productAssociationFactory,
private RepositoryInterface $productAssociationTypeRepository,
private readonly FactoryInterface $productAssociationFactory,
private readonly RepositoryInterface $productAssociationTypeRepository,
) {
}

public function getForProduct(ProductInterface $product): ProductAssociation
public function getForProduct(ProductInterface $product): ProductAssociationInterface
{
Assert::isInstanceOf($product, BoughtTogetherProductsAwareInterface::class);

Expand All @@ -36,6 +38,7 @@ public function getForProduct(ProductInterface $product): ProductAssociation
return $productAssociation;
}

/** @var ProductAssociationTypeInterface|null $productAssociationType */
$productAssociationType = $this->productAssociationTypeRepository->findOneBy([
'code' => BoughtTogetherProductsAwareInterface::BOUGHT_TOGETHER_ASSOCIATION_TYPE_CODE,
]);
Expand All @@ -44,6 +47,7 @@ public function getForProduct(ProductInterface $product): ProductAssociation
throw new BoughtTogetherAssociationTypeNotFoundException();
}

/** @var ProductAssociationInterface $productAssociation */
$productAssociation = $this->productAssociationFactory->createNew();
$productAssociation->setType($productAssociationType);
$product->addAssociation($productAssociation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace CommerceWeavers\SyliusAlsoBoughtPlugin\Provider;

use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductAssociation;
use Sylius\Component\Product\Model\ProductAssociationInterface;

interface BoughtTogetherProductsAssociationProviderInterface
{
public function getForProduct(ProductInterface $product): ProductAssociation;
public function getForProduct(ProductInterface $product): ProductAssociationInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use CommerceWeavers\SyliusAlsoBoughtPlugin\Entity\ProductSynchronizationInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

/** @extends RepositoryInterface<ProductSynchronizationInterface> */
interface ProductSynchronizationRepositoryInterface extends RepositoryInterface
{
public function findLastSynchronization(): ?ProductSynchronizationInterface;
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class DashboardContext implements Context
{
public function __construct (
public function __construct(
private readonly DashboardPageInterface $dashboardPage,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Context/Ui/Admin/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class ProductContext implements Context
{
public function __construct (
public function __construct(
private readonly BaseProductContext $productContext,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Behat/Element/Admin/ChannelFormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class ChannelFormElement extends Element implements ChannelFormElementInte
{
public function changeNumberOfSynchronisedProducts(int $number): void
{
$this->getElement('number_of_synchronised_products_input')->setValue($number);
$this->getElement('number_of_synchronised_products_input')->setValue((string) $number);
}

public function getNumberOfSynchronisedProducts(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use CommerceWeavers\SyliusAlsoBoughtPlugin\Saver\BoughtTogetherProductsInfoSaverInterface;
use CommerceWeavers\SyliusAlsoBoughtPlugin\Synchronizer\FrequentlyBoughtTogetherProductsSynchronizer;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Sylius\Component\Core\Model\Order;

Expand Down Expand Up @@ -53,9 +54,9 @@ public function testProductsSynchronization(): void
$productsMapper->map($secondOrder)->willReturn(['P12182' => ['P10273'], 'P10273' => ['P12182']]);
$productsMapper->map($thirdOrder)->willReturn(['P13757' => ['P10273']]);

$boughtTogetherProductsInfoSaver->save('P10273', ['P12182', 'P12183', 'P12182'])->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P12182', ['P10273', 'P12183', 'P10273'])->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P12183', ['P10273', 'P12182'])->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P10273', Argument::containing('P12182'))->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P12182', Argument::containing('P12183'))->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P12183', Argument::containing('P10273'))->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P13757', ['P10273'])->shouldBeCalled();

self::assertEquals(
Expand Down

0 comments on commit 516182b

Please sign in to comment.