Completed
Push — master ( da2f6e...d3b8cb )
by Kamil
20:06
created

SitemapSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 60
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_sitemap_interface() 0 4 1
A it_has_sitemap_urls() 0 5 1
A it_adds_url() 0 5 1
A it_removes_url() 0 12 1
A it_has_localization() 0 5 1
A it_has_last_modification_date() 0 5 1
A it_throws_sitemap_url_not_found_exception_if_cannot_find_url_to_remove() 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\Bundle\CoreBundle\Sitemap\Model;
13
 
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Bundle\CoreBundle\Sitemap\Exception\SitemapUrlNotFoundException;
16
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapInterface;
17
use Sylius\Bundle\CoreBundle\Sitemap\Model\SitemapUrlInterface;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
class SitemapSpec extends ObjectBehavior
23
{
24
    function it_is_initializable()
25
    {
26
        $this->shouldHaveType('Sylius\Bundle\CoreBundle\Sitemap\Model\Sitemap');
27
    }
28
29
    function it_implements_sitemap_interface()
30
    {
31
        $this->shouldImplement(SitemapInterface::class);
32
    }
33
34
    function it_has_sitemap_urls()
35
    {
36
        $this->setUrls([]);
37
        $this->getUrls()->shouldReturn([]);
38
    }
39
40
    function it_adds_url(SitemapUrlInterface $sitemapUrl)
41
    {
42
        $this->addUrl($sitemapUrl);
43
        $this->getUrls()->shouldReturn([$sitemapUrl]);
44
    }
45
46
    function it_removes_url(
47
        SitemapUrlInterface $sitemapUrl,
48
        SitemapUrlInterface $productUrl,
49
        SitemapUrlInterface $staticUrl
50
    ) {
51
        $this->addUrl($sitemapUrl);
52
        $this->addUrl($staticUrl);
53
        $this->addUrl($productUrl);
54
        $this->removeUrl($sitemapUrl);
55
56
        $this->getUrls()->shouldReturn([1 => $staticUrl, 2 => $productUrl]);
57
    }
58
59
    function it_has_localization()
60
    {
61
        $this->setLocalization('http://sylius.org/sitemap1.xml');
62
        $this->getLocalization()->shouldReturn('http://sylius.org/sitemap1.xml');
63
    }
64
65
    function it_has_last_modification_date(\DateTime $now)
66
    {
67
        $this->setLastModification($now);
68
        $this->getLastModification()->shouldReturn($now);
69
    }
70
71
    function it_throws_sitemap_url_not_found_exception_if_cannot_find_url_to_remove(
72
        SitemapUrlInterface $productUrl,
73
        SitemapUrlInterface $staticUrl
74
    ) {
75
        $this->addUrl($productUrl);
76
77
        $staticUrl->getLocalization()->willReturn('http://sylius.org');
78
79
        $this->shouldThrow(SitemapUrlNotFoundException::class)->during('removeUrl', [$staticUrl]);
80
    }
81
}
82