1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\RedirectBundle\Tests\Service; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Zenstruck\RedirectBundle\Service\NotFoundManager; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Kevin Bond <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class NotFoundManagerTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public const NOT_FOUND_DUMMY_CLASS = 'Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyNotFound'; |
15
|
|
|
|
16
|
|
|
private $om; |
17
|
|
|
|
18
|
|
|
private $repository; |
19
|
|
|
|
20
|
|
|
/** @var NotFoundManager */ |
21
|
|
|
private $notFoundManager; |
22
|
|
|
|
23
|
|
|
protected function setUp(): void |
24
|
|
|
{ |
25
|
|
|
$this->om = $this->createMock('Doctrine\Persistence\ObjectManager'); |
26
|
|
|
$this->repository = $this->createMock('Doctrine\Persistence\ObjectRepository'); |
27
|
|
|
|
28
|
|
|
$this->notFoundManager = new NotFoundManager(self::NOT_FOUND_DUMMY_CLASS, $this->om); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @test |
33
|
|
|
*/ |
34
|
|
|
public function create_not_found() |
35
|
|
|
{ |
36
|
|
|
$this->om->expects($this->once()) |
37
|
|
|
->method('persist') |
38
|
|
|
; |
39
|
|
|
|
40
|
|
|
$this->om->expects($this->once()) |
41
|
|
|
->method('flush') |
42
|
|
|
; |
43
|
|
|
|
44
|
|
|
$request = Request::create('https://example.com/foo/bar?baz=foo', 'GET', [], [], [], ['HTTP_REFERER' => 'https://google.com']); |
45
|
|
|
|
46
|
|
|
$notFound = $this->notFoundManager->createFromRequest($request); |
47
|
|
|
|
48
|
|
|
$this->assertSame('/foo/bar', $notFound->getPath()); |
49
|
|
|
$this->assertSame('https://example.com/foo/bar?baz=foo', $notFound->getFullUrl()); |
50
|
|
|
$this->assertSame('https://google.com', $notFound->getReferer()); |
51
|
|
|
$this->assertEqualsWithDelta(\time(), $notFound->getTimestamp()->format('U'), 1); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|