Completed
Push — 1.0-random-fixes ( 0c03ed )
by Kamil
28:28
created

TaxonSlugGeneratorSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_taxon_slug_generator_interface() 0 4 1
A it_generates_slug_for_root_taxon() 0 11 1
A it_generates_slug_for_root_taxon_replacing_apostrophes_with_hyphens() 0 11 1
A it_generates_slug_for_child_taxon_when_parent_taxon_already_has_slug() 0 16 1
A it_generates_slug_for_child_taxon_even_when_parent_taxon_does_not_have_slug() 0 19 1
A it_throws_an_exception_if_passed_taxon_has_no_name() 0 11 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Component\Taxonomy\Generator;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Taxonomy\Generator\TaxonSlugGeneratorInterface;
18
use Sylius\Component\Taxonomy\Model\TaxonInterface;
19
use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface;
20
21
final class TaxonSlugGeneratorSpec extends ObjectBehavior
22
{
23
    function it_implements_taxon_slug_generator_interface(): void
24
    {
25
        $this->shouldImplement(TaxonSlugGeneratorInterface::class);
26
    }
27
28
    function it_generates_slug_for_root_taxon(
29
        TaxonInterface $taxon,
30
        TaxonTranslationInterface $taxonTranslation
31
    ): void {
32
        $taxon->getTranslation('pl_PL')->willReturn($taxonTranslation);
33
        $taxonTranslation->getName()->willReturn('Board games');
34
35
        $taxon->getParent()->willReturn(null);
36
37
        $this->generate($taxon, 'pl_PL')->shouldReturn('board-games');
38
    }
39
40
    function it_generates_slug_for_root_taxon_replacing_apostrophes_with_hyphens(
41
        TaxonInterface $taxon,
42
        TaxonTranslationInterface $taxonTranslation
43
    ): void {
44
        $taxon->getTranslation('pl_PL')->willReturn($taxonTranslation);
45
        $taxonTranslation->getName()->willReturn('Rock\'n\'roll');
46
47
        $taxon->getParent()->willReturn(null);
48
49
        $this->generate($taxon, 'pl_PL')->shouldReturn('rock-n-roll');
50
    }
51
52
    function it_generates_slug_for_child_taxon_when_parent_taxon_already_has_slug(
53
        TaxonInterface $taxon,
54
        TaxonTranslationInterface $taxonTranslation,
55
        TaxonInterface $parentTaxon,
56
        TaxonTranslationInterface $parentTaxonTranslation
57
    ): void {
58
        $taxon->getTranslation('pl_PL')->willReturn($taxonTranslation);
59
        $taxonTranslation->getName()->willReturn('Battle games');
60
61
        $taxon->getParent()->willReturn($parentTaxon);
62
63
        $parentTaxon->getTranslation('pl_PL')->willReturn($parentTaxonTranslation);
64
        $parentTaxonTranslation->getSlug()->willReturn('board-games');
65
66
        $this->generate($taxon, 'pl_PL')->shouldReturn('board-games/battle-games');
67
    }
68
69
    function it_generates_slug_for_child_taxon_even_when_parent_taxon_does_not_have_slug(
70
        TaxonInterface $taxon,
71
        TaxonTranslationInterface $taxonTranslation,
72
        TaxonInterface $parentTaxon,
73
        TaxonTranslationInterface $parentTaxonTranslation
74
    ): void {
75
        $taxon->getTranslation('pl_PL')->willReturn($taxonTranslation);
76
        $taxonTranslation->getName()->willReturn('Battle games');
77
78
        $taxon->getParent()->willReturn($parentTaxon);
79
80
        $parentTaxon->getTranslation('pl_PL')->willReturn($parentTaxonTranslation);
81
        $parentTaxonTranslation->getSlug()->willReturn(null);
82
        $parentTaxonTranslation->getName()->willReturn('Board games');
83
84
        $parentTaxon->getParent()->willReturn(null);
85
86
        $this->generate($taxon, 'pl_PL')->shouldReturn('board-games/battle-games');
87
    }
88
89
    function it_throws_an_exception_if_passed_taxon_has_no_name(
90
        TaxonInterface $taxon,
91
        TaxonTranslationInterface $taxonTranslation
92
    ): void {
93
        $taxon->getTranslation('pl_PL')->willReturn($taxonTranslation);
94
        $taxonTranslation->getName()->willReturn('');
95
96
        $taxon->getParent()->willReturn(null);
97
98
        $this->shouldThrow(\InvalidArgumentException::class)->during('generate', [$taxon, 'pl_PL']);
99
    }
100
}
101