Skip to content

Commit

Permalink
Merge pull request Sylius#82 from patrick477/master
Browse files Browse the repository at this point in the history
 [General][Fixture][PHPUnit] Add testing and fixture
  • Loading branch information
bitbager authored Nov 12, 2017
2 parents 22831db + 8f0b051 commit d452ce8
Show file tree
Hide file tree
Showing 12 changed files with 1,011 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ script:
- composer validate --strict

- bin/phpspec run
- bin/phpunit
- bin/behat --strict -vvv --no-interaction || bin/behat --strict -vvv --no-interaction --rerun --tags="~@todo"

after_failure:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"lakion/mink-debug-extension": "^1.2.3",
"se/selenium-server-standalone": "^2.52",
"symplify/easy-coding-standard": "^2.4",
"sylius-labs/coding-standard": "^1.0"
"sylius-labs/coding-standard": "^1.0",
"matthiasnoback/symfony-config-test": "^2.1.0"
},
"prefer-stable": true,
"minimum-stability": "alpha",
Expand All @@ -40,4 +41,4 @@
"config": {
"bin-dir": "bin"
}
}
}
2 changes: 1 addition & 1 deletion src/Fixture/BlockFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->prototype('array')
->children()
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
->scalarNode('enabled')->defaultTrue()->end()
->booleanNode('enabled')->defaultTrue()->end()
->arrayNode('translations')
->prototype('array')
->children()
Expand Down
4 changes: 2 additions & 2 deletions src/Fixture/FrequentlyAskedQuestionFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->arrayNode('frequently_asked_questions')
->prototype('array')
->children()
->scalarNode('enabled')->defaultTrue()->end()
->scalarNode('position')->defaultNull()->end()
->booleanNode('enabled')->defaultTrue()->end()
->integerNode('position')->defaultNull()->end()
->arrayNode('translations')
->prototype('array')
->children()
Expand Down
2 changes: 1 addition & 1 deletion src/Fixture/PageFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
->arrayNode('pages')
->prototype('array')
->children()
->scalarNode('enabled')->defaultTrue()->end()
->booleanNode('enabled')->defaultTrue()->end()
->arrayNode('translations')
->prototype('array')
->children()
Expand Down
118 changes: 118 additions & 0 deletions src/Fixture/SectionFixture.php
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();
}
}
2 changes: 0 additions & 2 deletions src/Resources/config/fixture.yml

This file was deleted.

9 changes: 9 additions & 0 deletions src/Resources/config/services/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ services:
- "@bitbag.factory.frequently_asked_question"
- "@bitbag.factory.frequently_asked_question_translation"
- "@bitbag.repository.frequently_asked_question"
tags:
- { name: sylius_fixtures.fixture }

bitbag.fixture.section:
class: BitBag\CmsPlugin\Fixture\SectionFixture
arguments:
- "@bitbag.factory.section"
- "@bitbag.factory.section_translation"
- "@bitbag.repository.section"
tags:
- { name: sylius_fixtures.fixture }
Loading

0 comments on commit d452ce8

Please sign in to comment.