testGetParametersWithCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NewsBundle\Tests\Model;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\NewsBundle\Permalink\CollectionPermalink;
18
19
class CollectionPermalinkTest extends TestCase
20
{
21
    public function testGenerateWithCollection(): void
22
    {
23
        $collection = $this->createMock('Sonata\ClassificationBundle\Model\CollectionInterface');
24
        $collection->expects($this->any())->method('getSlug')->willReturn('the-collection');
25
26
        $post = $this->createMock('Sonata\NewsBundle\Model\PostInterface');
27
        $post->expects($this->any())->method('getCollection')->willReturn($collection);
28
        $post->expects($this->any())->method('getSlug')->willReturn('the-slug');
29
30
        $permalink = new CollectionPermalink();
31
        $this->assertSame('the-collection/the-slug', $permalink->generate($post));
32
    }
33
34
    public function testGenerateWithoutCollection(): void
35
    {
36
        $post = $this->createMock('Sonata\NewsBundle\Model\PostInterface');
37
        $post->expects($this->any())->method('getCollection')->willReturn(null);
38
        $post->expects($this->any())->method('getSlug')->willReturn('the-slug');
39
40
        $permalink = new CollectionPermalink();
41
        $this->assertSame('the-slug', $permalink->generate($post));
42
    }
43
44
    public function testGetParametersWithCollection(): void
45
    {
46
        $permalink = new CollectionPermalink();
47
        $expected = [
48
            'collection' => 'the-collection',
49
            'slug' => 'the-slug',
50
        ];
51
52
        $this->assertSame($expected, $permalink->getParameters('the-collection/the-slug'));
53
    }
54
55
    public function testGetParametersWithoutCollection(): void
56
    {
57
        $permalink = new CollectionPermalink();
58
        $expected = [
59
            'collection' => null,
60
            'slug' => 'the-slug',
61
        ];
62
63
        $this->assertSame($expected, $permalink->getParameters('the-slug'));
64
    }
65
66
    public function testGetParametersWithoutCollectionAndExtra(): void
67
    {
68
        $this->expectException('InvalidArgumentException');
69
70
        $permalink = new CollectionPermalink();
71
        $expected = [
72
            'collection' => 'the-collection',
73
            'slug' => 'the-slug',
74
        ];
75
76
        $this->assertSame($expected, $permalink->getParameters('the-collection/the-slug/asdsaasds'));
77
    }
78
}
79