Skip to content

Commit

Permalink
[SequenceSpec] Missing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
arnolanglade committed Dec 9, 2014
1 parent 315def4 commit 8d89d2e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Sylius/Bundle/SequenceBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
"sylius/sequence": "0.12.*@dev"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
"phpspec/phpspec": "~2.1@dev"
},
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": { "Sylius\\Bundle\\SequenceBundle\\": "" }
},
"autoload-dev": {
"psr-4": { "spec\\Sylius\\Bundle\\SequenceBundle\\": "spec/" }
},
"extra": {
"branch-alias": {
"dev-master": "0.12-dev"
Expand Down
92 changes: 92 additions & 0 deletions src/Sylius/Bundle/SequenceBundle/spec/NumberListenerSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace spec\Sylius\Bundle\SequenceBundle\Doctrine\ORM;

use Doctrine\ORM\EntityManager;
use PhpSpec\ObjectBehavior;
use Doctrine\ORM\Events;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\Common\EventManager;
use Prophecy\Argument;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Sequence\Model\Sequence;
use Sylius\Component\Sequence\Model\SequenceSubjectInterface;
use Sylius\Component\Registry\ServiceRegistryInterface;
use Sylius\Component\Sequence\Number\GeneratorInterface;
use Sylius\Component\Sequence\SyliusSequenceEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* @author Arnaud Langlade <arn0d.dev@gmail.com>
*/
class NumberListenerSpec extends ObjectBehavior
{
function let(
ServiceRegistryInterface $registry,
EventManager $eventManager,
EventDispatcherInterface $eventDispatcher
) {
$this->beConstructedWith(
$registry,
$eventManager,
$eventDispatcher,
'Sylius\Component\Sequence\Model\Sequence'
);
}

function it_enable_listener_on_specific_entity(SequenceSubjectInterface $subject, $eventManager)
{
$eventManager->addEventListener(
Events::preFlush,
Argument::type('Sylius\Bundle\SequenceBundle\Doctrine\ORM\NumberListener')
)->shouldBeCalled();

$this->enableEntity($subject);
}

function it_applies_generator(
PreFlushEventArgs $args,
EntityManager $entityManager,
SequenceSubjectInterface $entity,
GeneratorInterface $generator,
EntityRepository $sequenceRepository,
Sequence $sequence,
$registry,
$eventDispatcher
) {
$this->enableEntity($entity);

$args->getEntityManager()->willReturn($entityManager);

$registry->get($entity)
->willReturn($generator);

$entity->getSequenceType()->willReturn('sequence_type');

$entityManager->getRepository('Sylius\Component\Sequence\Model\Sequence')->willReturn($sequenceRepository);
$sequenceRepository->findOneBy(array('type' => 'sequence_type'))->willReturn($sequence);

$eventDispatcher->dispatch(
sprintf(SyliusSequenceEvents::PRE_GENERATE, 'sequence_type'),
Argument::type('Symfony\Component\EventDispatcher\GenericEvent')
)->shouldBeCalled();

$generator->generate($entity, '')->shouldBeCalled();

$eventDispatcher->dispatch(
sprintf(SyliusSequenceEvents::POST_GENERATE, 'sequence_type'),
Argument::type('Symfony\Component\EventDispatcher\GenericEvent')
)->shouldBeCalled();

$this->preFlush($args);
}
}

0 comments on commit 8d89d2e

Please sign in to comment.