minor #17392 [Behat] Dehardcode the use of entities (GSadee)

This PR was merged into the 1.14 branch.

Discussion
----------

| Q               | A
|-----------------|-----
| Branch?         | 1.14
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no<!-- don't forget to update the UPGRADE-*.md file -->
| Related tickets | 
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.13 branch
 - Features and deprecations must be submitted against the 1.14 branch
 - Features, removing deprecations and BC breaks must be submitted against the 2.0 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------
  [Behat] Dehardcode the use of AvatarImage entity
  [Behat] Dehardcode the use of ShopBillingData entity
  Improve DefaultChannelFactory test service + add note about change
This commit is contained in:
Karol 2024-10-31 13:00:35 +01:00 committed by GitHub
commit 0ddf30b58f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 72 additions and 27 deletions

View file

@ -1035,3 +1035,27 @@
* `sylius.{user_type}_user.pin_generator.password_reset`
* `sylius.{user_type}_user.pin_uniqueness_checker.password_reset`
### Testing Suite
1. The constructor signature of `Sylius\Component\Core\Test\Services\DefaultChannelFactory` has been changed:
```diff
public function __construct(
- private ChannelFactoryInterface $channelFactory,
- private FactoryInterface $currencyFactory,
- private FactoryInterface $localeFactory,
- private RepositoryInterface $channelRepository,
- private RepositoryInterface $currencyRepository,
- private RepositoryInterface $localeRepository,
- private string $defaultLocaleCode,
+ private readonly ChannelFactoryInterface $channelFactory,
+ private readonly FactoryInterface $currencyFactory,
+ private readonly FactoryInterface $localeFactory,
+ private readonly FactoryInterface $shopBillingDataFactory,
+ private readonly RepositoryInterface $channelRepository,
+ private readonly RepositoryInterface $currencyRepository,
+ private readonly RepositoryInterface $localeRepository,
+ private readonly string $defaultLocaleCode,
)
```

View file

@ -18,20 +18,26 @@ use Doctrine\Persistence\ObjectManager;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
use Sylius\Component\Core\Model\AdminUserInterface;
use Sylius\Component\Core\Model\AvatarImage;
use Sylius\Component\Core\Model\AvatarImageInterface;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;
use Sylius\Resource\Factory\FactoryInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
final class AdminUserContext implements Context
{
/**
* @param UserRepositoryInterface<AdminUserInterface> $userRepository
* @param FactoryInterface<AvatarImageInterface> $avatarImageFactory
*/
public function __construct(
private SharedStorageInterface $sharedStorage,
private ExampleFactoryInterface $userFactory,
private UserRepositoryInterface $userRepository,
private ImageUploaderInterface $imageUploader,
private ObjectManager $objectManager,
private \ArrayAccess $minkParameters,
private readonly SharedStorageInterface $sharedStorage,
private readonly ExampleFactoryInterface $userFactory,
private readonly UserRepositoryInterface $userRepository,
private readonly ImageUploaderInterface $imageUploader,
private readonly ObjectManager $objectManager,
private readonly \ArrayAccess $minkParameters,
private readonly FactoryInterface $avatarImageFactory,
) {
}
@ -99,7 +105,7 @@ final class AdminUserContext implements Context
{
$filesPath = $this->minkParameters['files_path'];
$avatar = new AvatarImage();
$avatar = $this->avatarImageFactory->createNew();
$avatar->setFile(new UploadedFile($filesPath . $avatarPath, basename($avatarPath)));
$this->imageUploader->upload($avatar);

View file

@ -23,23 +23,26 @@ use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Formatter\StringInflector;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopBillingData;
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Resource\Factory\FactoryInterface;
final class ChannelContext implements Context
{
/**
* @param ChannelRepositoryInterface<ChannelInterface> $channelRepository
* @param FactoryInterface<ShopBillingDataInterface> $shopBillingDataFactory
*/
public function __construct(
private SharedStorageInterface $sharedStorage,
private ChannelContextSetterInterface $channelContextSetter,
private DefaultChannelFactoryInterface $unitedStatesChannelFactory,
private DefaultChannelFactoryInterface $defaultChannelFactory,
private ChannelRepositoryInterface $channelRepository,
private ObjectManager $channelManager,
private readonly SharedStorageInterface $sharedStorage,
private readonly ChannelContextSetterInterface $channelContextSetter,
private readonly DefaultChannelFactoryInterface $unitedStatesChannelFactory,
private readonly DefaultChannelFactoryInterface $defaultChannelFactory,
private readonly ChannelRepositoryInterface $channelRepository,
private readonly ObjectManager $channelManager,
private readonly FactoryInterface $shopBillingDataFactory,
) {
}
@ -243,7 +246,7 @@ final class ChannelContext implements Context
CountryInterface $country,
string $taxId,
): void {
$shopBillingData = new ShopBillingData();
$shopBillingData = $this->shopBillingDataFactory->createNew();
$shopBillingData->setCompany($company);
$shopBillingData->setStreet($street);
$shopBillingData->setPostcode($postcode);

View file

@ -28,6 +28,7 @@
<argument type="service" id="sylius.uploader.image" />
<argument type="service" id="doctrine.orm.entity_manager" />
<argument type="service" id="behat.mink.parameters" />
<argument type="service" id="sylius.factory.avatar_image" />
</service>
<service id="sylius.behat.context.setup.cart" class="Sylius\Behat\Context\Setup\CartContext">
@ -54,6 +55,7 @@
<argument type="service" id="sylius.behat.factory.default_channel" />
<argument type="service" id="sylius.repository.channel" />
<argument type="service" id="sylius.manager.channel" />
<argument type="service" id="sylius.factory.shop_billing_data" />
</service>
<service id="sylius.behat.context.setup.currency" class="Sylius\Behat\Context\Setup\CurrencyContext">

View file

@ -36,10 +36,12 @@
<argument type="service" id="sylius.factory.zone" />
<argument>%locale%</argument>
</service>
<service id="sylius.behat.factory.default_channel" class="Sylius\Component\Core\Test\Services\DefaultChannelFactory">
<argument type="service" id="sylius.factory.channel" />
<argument type="service" id="sylius.factory.currency" />
<argument type="service" id="sylius.factory.locale" />
<argument type="service" id="sylius.factory.shop_billing_data" />
<argument type="service" id="sylius.repository.channel" />
<argument type="service" id="sylius.repository.currency" />
<argument type="service" id="sylius.repository.locale" />

View file

@ -15,7 +15,7 @@ namespace Sylius\Component\Core\Test\Services;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopBillingData;
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Resource\Doctrine\Persistence\RepositoryInterface;
@ -32,18 +32,20 @@ final class DefaultChannelFactory implements DefaultChannelFactoryInterface
/**
* @param FactoryInterface<CurrencyInterface> $currencyFactory
* @param FactoryInterface<LocaleInterface> $localeFactory
* @param FactoryInterface<ShopBillingDataInterface> $shopBillingDataFactory
* @param RepositoryInterface<ChannelInterface> $channelRepository
* @param RepositoryInterface<CurrencyInterface> $currencyRepository
* @param RepositoryInterface<LocaleInterface> $localeRepository
*/
public function __construct(
private ChannelFactoryInterface $channelFactory,
private FactoryInterface $currencyFactory,
private FactoryInterface $localeFactory,
private RepositoryInterface $channelRepository,
private RepositoryInterface $currencyRepository,
private RepositoryInterface $localeRepository,
private string $defaultLocaleCode,
private readonly ChannelFactoryInterface $channelFactory,
private readonly FactoryInterface $currencyFactory,
private readonly FactoryInterface $localeFactory,
private readonly FactoryInterface $shopBillingDataFactory,
private readonly RepositoryInterface $channelRepository,
private readonly RepositoryInterface $currencyRepository,
private readonly RepositoryInterface $localeRepository,
private readonly string $defaultLocaleCode,
) {
}
@ -63,7 +65,7 @@ final class DefaultChannelFactory implements DefaultChannelFactoryInterface
$channel->addLocale($locale);
$channel->setDefaultLocale($locale);
if ($channel->getShopBillingData() === null) {
$channel->setShopBillingData(new ShopBillingData());
$channel->setShopBillingData($this->shopBillingDataFactory->createNew());
}
$this->channelRepository->add($channel);

View file

@ -16,7 +16,7 @@ namespace spec\Sylius\Component\Core\Test\Services;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Factory\ChannelFactoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopBillingData;
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Sylius\Component\Core\Test\Services\DefaultChannelFactoryInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
@ -32,11 +32,13 @@ final class DefaultChannelFactorySpec extends ObjectBehavior
RepositoryInterface $channelRepository,
RepositoryInterface $currencyRepository,
RepositoryInterface $localeRepository,
FactoryInterface $shopBillingDataFactory,
): void {
$this->beConstructedWith(
$channelFactory,
$currencyFactory,
$localeFactory,
$shopBillingDataFactory,
$channelRepository,
$currencyRepository,
$localeRepository,
@ -53,12 +55,14 @@ final class DefaultChannelFactorySpec extends ObjectBehavior
ChannelFactoryInterface $channelFactory,
FactoryInterface $currencyFactory,
FactoryInterface $localeFactory,
FactoryInterface $shopBillingDataFactory,
RepositoryInterface $channelRepository,
RepositoryInterface $currencyRepository,
RepositoryInterface $localeRepository,
ChannelInterface $channel,
CurrencyInterface $currency,
LocaleInterface $locale,
ShopBillingDataInterface $shopBillingData,
): void {
$localeFactory->createNew()->willReturn($locale);
$locale->setCode('en_US')->shouldBeCalled();
@ -68,6 +72,8 @@ final class DefaultChannelFactorySpec extends ObjectBehavior
$channelFactory->createNamed('Default')->willReturn($channel);
$shopBillingDataFactory->createNew()->willReturn($shopBillingData);
$channel->setCode('DEFAULT')->shouldBeCalled();
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();
@ -76,7 +82,7 @@ final class DefaultChannelFactorySpec extends ObjectBehavior
$channel->addLocale($locale)->shouldBeCalled();
$channel->setDefaultLocale($locale)->shouldBeCalled();
$channel->getShopBillingData()->willReturn(null);
$channel->setShopBillingData(new ShopBillingData())->shouldBeCalled();
$channel->setShopBillingData($shopBillingData)->shouldBeCalled();
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);