CanonicalUrlGeneratorTest::testGenerateUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Palmtree\CanonicalUrlBundle\Tests\Service;
4
5
use Palmtree\CanonicalUrlBundle\Service\CanonicalUrlGenerator;
6
use Palmtree\CanonicalUrlBundle\Tests\AbstractTest;
7
8
class CanonicalUrlGeneratorTest extends AbstractTest
9
{
10
    /**
11
     * @dataProvider configProvider
12
     *
13
     * @param array $config
14
     */
15
    public function testGenerateUrl(array $config)
16
    {
17
        $urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config);
18
19
        $url = $urlGenerator->generate('foo');
20
21
        $this->assertEquals('https://example.org/foo', $url);
22
    }
23
24
    /**
25
     * @dataProvider configProvider
26
     *
27
     * @param array $config
28
     */
29
    public function testGenerateUrlWithStringParams(array $config)
30
    {
31
        $urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config);
32
33
        $url = $urlGenerator->generate('foo', 'key1=val1&key2=val2');
34
35
        $this->assertEquals('https://example.org/foo?key1=val1&key2=val2', $url);
36
    }
37
38
    /**
39
     * @dataProvider configProvider
40
     *
41
     * @param array $config
42
     */
43
    public function testNonExistentRouteThrowsException(array $config)
44
    {
45
        $this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
46
        $urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config);
47
48
        $urlGenerator->generate('bar');
49
    }
50
51
    /**
52
     * @dataProvider configProvider
53
     *
54
     * @param array $config
55
     */
56
    public function testEmptyRouteReturnsEmptyString(array $config)
57
    {
58
        $urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config);
59
60
        $url = $urlGenerator->generate('');
61
62
        $this->assertSame('', $url);
63
    }
64
}
65