forked from Sylius/AdminOrderCreationPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Sylius#82 from patrick477/master
[General][Fixture][PHPUnit] Add testing and fixture
- Loading branch information
Showing
12 changed files
with
1,011 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/** | ||
* This file was created by the developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\CmsPlugin\Fixture; | ||
|
||
use BitBag\CmsPlugin\Entity\SectionInterface; | ||
use BitBag\CmsPlugin\Entity\SectionTranslationInterface; | ||
use BitBag\CmsPlugin\Repository\SectionRepositoryInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @author Patryk Drapik <[email protected]> | ||
*/ | ||
final class SectionFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var FactoryInterface | ||
*/ | ||
private $sectionFactory; | ||
|
||
/** | ||
* @var FactoryInterface | ||
*/ | ||
private $sectionTranslationFactory; | ||
|
||
/** | ||
* @var SectionRepositoryInterface | ||
*/ | ||
private $sectionRepository; | ||
|
||
/** | ||
* @param FactoryInterface $sectionFactory | ||
* @param FactoryInterface $sectionTranslationFactory | ||
* @param SectionRepositoryInterface $sectionRepository | ||
*/ | ||
public function __construct( | ||
FactoryInterface $sectionFactory, | ||
FactoryInterface $sectionTranslationFactory, | ||
SectionRepositoryInterface $sectionRepository | ||
) | ||
{ | ||
$this->sectionFactory = $sectionFactory; | ||
$this->sectionTranslationFactory = $sectionTranslationFactory; | ||
$this->sectionRepository = $sectionRepository; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function load(array $options): void | ||
{ | ||
foreach ($options['sections'] as $code => $fields) { | ||
|
||
if (null !== $this->sectionRepository->findOneBy(['code' => $code])) { | ||
continue; | ||
} | ||
|
||
/** @var SectionInterface $section */ | ||
$section = $this->sectionFactory->createNew(); | ||
|
||
$section->setCode($code); | ||
|
||
foreach ($fields['translations'] as $localeCode => $translation) { | ||
/** @var SectionTranslationInterface $sectionTranslation */ | ||
$sectionTranslation = $this->sectionTranslationFactory->createNew(); | ||
|
||
$sectionTranslation->setName($translation['name']); | ||
|
||
$section->addTranslation($sectionTranslation); | ||
} | ||
|
||
$this->sectionRepository->add($section); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'bitbag_cms_section'; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void | ||
{ | ||
$optionsNode | ||
->children() | ||
->arrayNode('sections') | ||
->prototype('array') | ||
->children() | ||
->arrayNode('translations') | ||
->prototype('array') | ||
->children() | ||
->scalarNode('name')->defaultNull()->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.