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

[ProductBundle] Fix default repository for sylius product association type #10379

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ sylius_product:
product_option:
classes:
repository: Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductOptionRepository
product_association_type:
classes:
repository: Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductAssociationTypeRepository
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius.repository.product.class">Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductRepository</parameter>
<parameter key="sylius.repository.product_association_type.class">Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductAssociationTypeRepository</parameter>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we then remove this configuration? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lchrusciel @GSadee Ok with that ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should :)

Copy link
Member Author

@loic425 loic425 May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lchrusciel @Zales0123
This doesn't work... we forgot something...
This line returns EntityRepository.

However this following command

bin/console debug:container | grep repository.product_association_type

returns
sylius.repository.product_association_type Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductAssociationTypeRepository
sylius.repository.product_association_type_translation Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is the right repository on ResourceController.

<parameter key="sylius.repository.product_variant.class">Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductVariantRepository</parameter>
<parameter key="sylius.repository.product_attribute.class">Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository</parameter>
<parameter key="sylius.repository.product_option.class">Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductOptionRepository</parameter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
namespace Sylius\Bundle\ProductBundle\Tests;

use PHPUnit\Framework\Assert;
use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductAssociationTypeRepository;
use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductOptionRepository;
use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductRepository;
use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductVariantRepository;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -38,4 +43,26 @@ public function its_services_are_initializable(): void
Assert::assertNotNull($container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE));
}
}

/**
* @test
*/
public function it_initializes_default_doctrine_repositories(): void
{
/** @var ContainerBuilder $container */
$container = self::createClient()->getContainer();

$repositories = [
'sylius.repository.product' => ProductRepository::class,
'sylius.repository.product_association_type' => ProductAssociationTypeRepository::class,
'sylius.repository.product_variant' => ProductVariantRepository::class,
'sylius.repository.product_attribute' => EntityRepository::class,
'sylius.repository.product_option' => ProductOptionRepository::class,
];

foreach ($repositories as $id => $class) {
$service = $container->get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE);
Assert::assertEquals(get_class($service), $class);
}
}
}