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
|
|
|
* @param array $config |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
public function testGenerateUrl(array $config) |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
$urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config); |
17
|
|
|
|
18
|
|
|
$url = $urlGenerator->generate('foo'); |
19
|
|
|
|
20
|
|
|
$this->assertEquals('https://example.org/foo', $url); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @dataProvider configProvider |
25
|
|
|
* @param array $config |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function testGenerateUrlWithStringParams(array $config) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config); |
30
|
|
|
|
31
|
|
|
$url = $urlGenerator->generate('foo', 'key1=val1&key2=val2'); |
32
|
|
|
|
33
|
|
|
$this->assertEquals('https://example.org/foo?key1=val1&key2=val2', $url); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider configProvider |
38
|
|
|
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException |
39
|
|
|
* @param array $config |
40
|
|
|
*/ |
41
|
|
|
public function testNonExistentRouteThrowsException(array $config) |
42
|
|
|
{ |
43
|
|
|
$urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config); |
44
|
|
|
|
45
|
|
|
$urlGenerator->generate('bar'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider configProvider |
50
|
|
|
* @param array $config |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function testEmptyRouteReturnsEmptyString(array $config) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$urlGenerator = new CanonicalUrlGenerator($this->getRouter(), $config); |
55
|
|
|
|
56
|
|
|
$url = $urlGenerator->generate(''); |
57
|
|
|
|
58
|
|
|
$this->assertSame('', $url); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.