Completed
Push — remove-content-bundle ( 201341 )
by Kamil
34:43
created

TaxonSlugGeneratorSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_taxon_slug_generator_interface() 0 4 1
A it_generates_slug_based_on_new_taxon_name_and_parent_taxon_slug() 0 9 1
A it_generates_slug_based_on_new_taxon_name_if_this_taxon_has_no_parent() 0 4 1
A it_throws_exception_if_parent_taxon_with_given_id_does_not_exist() 0 10 1
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\Component\Taxonomy\Generator;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Taxonomy\Generator\TaxonSlugGenerator;
16
use Sylius\Component\Taxonomy\Generator\TaxonSlugGeneratorInterface;
17
use Sylius\Component\Taxonomy\Model\TaxonInterface;
18
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
final class TaxonSlugGeneratorSpec extends ObjectBehavior
24
{
25
    function let(TaxonRepositoryInterface $taxonRepository)
26
    {
27
        $this->beConstructedWith($taxonRepository);
28
    }
29
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType(TaxonSlugGenerator::class);
33
    }
34
35
    function it_implements_taxon_slug_generator_interface()
36
    {
37
        $this->shouldImplement(TaxonSlugGeneratorInterface::class);
38
    }
39
40
    function it_generates_slug_based_on_new_taxon_name_and_parent_taxon_slug(
41
        TaxonInterface $parent,
42
        TaxonRepositoryInterface $taxonRepository
43
    ) {
44
        $taxonRepository->find(1)->willReturn($parent);
45
        $parent->getSlug()->willReturn('board-games');
46
47
        $this->generate('Battle games', 1)->shouldReturn('board-games/battle-games');;
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
48
    }
49
50
    function it_generates_slug_based_on_new_taxon_name_if_this_taxon_has_no_parent()
51
    {
52
        $this->generate('Board games')->shouldReturn('board-games');;
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
53
    }
54
55
    function it_throws_exception_if_parent_taxon_with_given_id_does_not_exist(
56
        TaxonRepositoryInterface $taxonRepository
57
    ) {
58
        $taxonRepository->find(1)->willReturn(null);
59
60
        $this
61
            ->shouldThrow(new \InvalidArgumentException('There is no parent taxon with id 1.'))
62
            ->during('generate', ['Battle games', 1])
63
        ;
64
    }
65
}
66