Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for builds #73

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
lchrusciel marked this conversation as resolved.
Show resolved Hide resolved
*/
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();
lchrusciel marked this conversation as resolved.
Show resolved Hide resolved
$boughtTogetherProductsInfoSaver->save('P12182', Argument::containing('P12183'))->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P12183', Argument::containing('P10273'))->shouldBeCalled();
$boughtTogetherProductsInfoSaver->save('P13757', ['P10273'])->shouldBeCalled();

self::assertEquals(
Expand Down
Loading