Skip to content

Instantly share code, notes, and snippets.

@koemeet
Created February 24, 2016 15:13
Show Gist options
  • Save koemeet/677fc3a2e95b445fadbd to your computer and use it in GitHub Desktop.
Save koemeet/677fc3a2e95b445fadbd to your computer and use it in GitHub Desktop.
<?php
namespace spec\Mango\Bundle\CoreBundle\Mailer\Provider;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Mailer\Model\EmailInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
class EmailProviderSpec extends ObjectBehavior
{
function let(
RepositoryInterface $emailRepository,
FactoryInterface $emailFactory
) {
$this->beConstructedWith(
$emailRepository,
$emailFactory,
[
'order_confirmation' => [
'subject' => 'Thanks for your order!',
'content' => 'We are so glad that you ordered something.',
],
]
);
}
function it_is_initializable()
{
$this->shouldHaveType('Mango\Bundle\CoreBundle\Mailer\Provider\EmailProvider');
}
function it_gets_email_from_repository_if_it_exists(
$emailRepository,
EmailInterface $email
) {
$emailRepository
->findOneBy([
'code' => 'order_confirmation',
])
->shouldBeCalled()
->willReturn($email)
;
$this->getEmail('order_confirmation')
->shouldReturn($email)
;
}
function it_gets_email_from_static_defined_email_if_it_does_not_exist(
$emailRepository,
$emailFactory,
EmailInterface $email
) {
$emailRepository
->findOneBy([
'code' => 'order_confirmation',
])
->shouldBeCalled()
->willReturn(null)
;
$emailFactory->createNew()
->shouldBeCalled()
->willReturn($email)
;
$email->setCode('order_confirmation')
->shouldBeCalled()
;
$email->setSubject('Thanks for your order!')
->shouldBeCalled()
;
$email->setContent('We are so glad that you ordered something.')
->shouldBeCalled()
;
$this->getEmail('order_confirmation')
->shouldReturn($email)
;
}
function it_throws_correct_exception_when_email_doest_not_exist(
$emailRepository
) {
$emailRepository
->findOneBy([
'code' => 'non_existing',
])
->shouldBeCalled()
->willReturn(null)
;
$this->shouldThrow('\InvalidArgumentException')
->during('getEmail', ['non_existing'])
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment