Skip to content

Commit f8031da

Browse files
author
Damian D'amico
authored
Merge pull request #12 from odiseoteam/feature/fixture-banner-with-taxons
now it's possible to add taxons to banners fixtures
2 parents 987e8f7 + 692ad57 commit f8031da

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Fixture/BannerFixture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected function configureResourceNode(ArrayNodeDefinition $resourceNode): voi
1919
$node->arrayNode('channels')->scalarPrototype();
2020
$node->scalarNode('image');
2121
$node->scalarNode('mobile_image');
22+
$node->arrayNode('taxons')->scalarPrototype();
2223
}
2324

2425
/**

src/Fixture/Factory/BannerExampleFactory.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Sylius\Component\Locale\Model\LocaleInterface;
1414
use Sylius\Component\Resource\Factory\FactoryInterface;
1515
use Sylius\Component\Resource\Repository\RepositoryInterface;
16+
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
1617
use Symfony\Component\Config\FileLocatorInterface;
1718
use Symfony\Component\HttpFoundation\File\UploadedFile;
1819
use Symfony\Component\OptionsResolver\Options;
@@ -26,6 +27,9 @@ final class BannerExampleFactory extends AbstractExampleFactory
2627
/** @var ChannelRepositoryInterface */
2728
private $channelRepository;
2829

30+
/** @var TaxonRepositoryInterface */
31+
private $taxonRepository;
32+
2933
/** @var RepositoryInterface */
3034
private $localeRepository;
3135

@@ -41,11 +45,13 @@ final class BannerExampleFactory extends AbstractExampleFactory
4145
public function __construct(
4246
FactoryInterface $bannerFactory,
4347
ChannelRepositoryInterface $channelRepository,
48+
TaxonRepositoryInterface $taxonRepository,
4449
RepositoryInterface $localeRepository,
4550
?FileLocatorInterface $fileLocator = null
4651
) {
4752
$this->bannerFactory = $bannerFactory;
4853
$this->channelRepository = $channelRepository;
54+
$this->taxonRepository = $taxonRepository;
4955
$this->localeRepository = $localeRepository;
5056
$this->fileLocator = $fileLocator;
5157

@@ -74,6 +80,10 @@ protected function configureOptions(OptionsResolver $resolver): void
7480
return __DIR__.'/../../Resources/fixtures/banner/mobile-images/0'.rand(1, 4).'.png';
7581
})
7682
->setAllowedTypes('mobile_image', ['string'])
83+
84+
->setDefault('taxons', [])
85+
->setAllowedTypes('taxons', 'array')
86+
->setNormalizer('taxons', LazyOption::findBy($this->taxonRepository, 'code'))
7787
;
7888
}
7989

@@ -92,6 +102,10 @@ public function create(array $options = []): BannerInterface
92102
$banner->addChannel($channel);
93103
}
94104

105+
foreach ($options['taxons'] as $taxon) {
106+
$banner->addTaxon($taxon);
107+
}
108+
95109
/** @var string $localeCode */
96110
foreach ($this->getLocales() as $localeCode) {
97111
$banner->setCurrentLocale($localeCode);

src/Resources/config/services/fixture.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ services:
1212
arguments:
1313
- '@odiseo_sylius_banner_plugin.factory.banner'
1414
- '@sylius.repository.channel'
15+
- '@sylius.repository.taxon'
1516
- '@sylius.repository.locale'
1617
- '@file_locator'

0 commit comments

Comments
 (0)