1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\RedirectBundle\Tests\Model; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Kevin Bond <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class NotFoundTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider pathProvider |
14
|
|
|
* |
15
|
|
|
* @test |
16
|
|
|
*/ |
17
|
|
|
public function constructor($path, $expectedPath) |
18
|
|
|
{ |
19
|
|
|
$notFound = $this->createNotFound($path, 'http://foobar.com/baz'); |
20
|
|
|
|
21
|
|
|
$this->assertSame($expectedPath, $notFound->getPath()); |
22
|
|
|
$this->assertNull($notFound->getReferer()); |
23
|
|
|
$this->assertSame('http://foobar.com/baz', $notFound->getFullUrl()); |
24
|
|
|
$this->assertEqualsWithDelta(\time(), $notFound->getTimestamp()->format('U'), 1); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
View Code Duplication |
public function pathProvider() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
return [ |
30
|
|
|
['foo/bar', '/foo/bar'], |
31
|
|
|
['/foo/bar/', '/foo/bar/'], |
32
|
|
|
['foo', '/foo'], |
33
|
|
|
['foo/bar ', '/foo/bar'], |
34
|
|
|
[' foo/bar/', '/foo/bar/'], |
35
|
|
|
[' /foo', '/foo'], |
36
|
|
|
['http://www.example.com/foo', '/foo'], |
37
|
|
|
['http://www.example.com/', '/'], |
38
|
|
|
['http://www.example.com', '/'], |
39
|
|
|
['foo/bar?baz=true', '/foo/bar'], |
40
|
|
|
['http://www.example.com/foo?baz=bar&foo=baz', '/foo'], |
41
|
|
|
['http://www.example.com/foo?baz=bar&foo=baz#baz', '/foo'], |
42
|
|
|
['', null], |
43
|
|
|
[' ', null], |
44
|
|
|
['/', '/'], |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return \Zenstruck\RedirectBundle\Model\NotFound |
50
|
|
|
*/ |
51
|
|
|
private function createNotFound($path, $fullUrl, $referer = null, \DateTime $timestamp = null) |
52
|
|
|
{ |
53
|
|
|
return $this->getMockForAbstractClass( |
54
|
|
|
'Zenstruck\RedirectBundle\Model\NotFound', |
55
|
|
|
[$path, $fullUrl, $referer, $timestamp] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.