NotFoundManagerTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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