Completed
Push — master ( b70f30...259e2d )
by Kamil
32:06
created

PromotionContextSpec::it_gets_coupon_by_its_code()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Behat\Context\Transform;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\ObjectBehavior;
16
use Prophecy\Argument;
17
use Sylius\Behat\Context\Transform\PromotionContext;
18
use Sylius\Component\Promotion\Model\PromotionInterface;
19
use Sylius\Component\Promotion\Repository\PromotionRepositoryInterface;
20
21
/**
22
 * @mixin PromotionContext
23
 *
24
 * @author Jan Góralski <[email protected]>
25
 */
26
class PromotionContextSpec extends ObjectBehavior
27
{
28
    function let(PromotionRepositoryInterface $promotionRepository)
29
    {
30
        $this->beConstructedWith($promotionRepository);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType('Sylius\Behat\Context\Transform\PromotionContext');
36
    }
37
38
    function it_implements_context_interface()
39
    {
40
        $this->shouldImplement(Context::class);
41
    }
42
43
    function it_gets_promotion_by_its_name(
44
        PromotionRepositoryInterface $promotionRepository,
45
        PromotionInterface $promotion
46
    ) {
47
        $promotion->getName()->willReturn('Best Promotion');
48
        $promotionRepository->findOneBy(['name' => 'Best Promotion'])->willReturn($promotion);
49
50
        $this->getPromotionByName('Best Promotion');
51
    }
52
53
    function it_throws_exception_when_promotion_with_given_name_was_not_found(
54
        PromotionRepositoryInterface $promotionRepository
55
    ) {
56
        $promotionRepository->findOneBy(['name' => 'Wrong Promotion'])->willReturn(null);
57
58
        $this->shouldThrow(\InvalidArgumentException::class)->during('getPromotionByName', ['Wrong Promotion']);
59
    }
60
}
61