Completed
Push — ezp_31499_ez_path_ez_url ( 80f1d5 )
by
unknown
12:51
created

RoutingExtensionTest::getExampleContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\MVC\Symfony\Templating\Tests\Twig\Extension;
10
11
use eZ\Publish\API\Repository\Values\Content\Content as APIContent;
12
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
13
use eZ\Publish\API\Repository\Values\Content\Location as APILocation;
14
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator;
15
use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGeneratorInterface;
16
use eZ\Publish\Core\MVC\Symfony\Routing\RouteReference;
17
use eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\RoutingExtension;
18
use eZ\Publish\Core\Repository\Values\Content\Content;
19
use eZ\Publish\Core\Repository\Values\Content\Location;
20
use eZ\Publish\Core\Repository\Values\Content\VersionInfo;
21
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\HttpFoundation\RequestStack;
24
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
25
use Twig\Test\IntegrationTestCase;
26
27
final class RoutingExtensionTest extends IntegrationTestCase
28
{
29
    protected function getExtensions(): array
30
    {
31
        return [
32
            new RoutingExtension(
33
                $this->getRouteReferenceGenerator(),
34
                $this->getUrlGenerator()
35
            ),
36
        ];
37
    }
38
39
    protected function getFixturesDir(): string
40
    {
41
        return __DIR__ . '/_fixtures/routing_functions';
42
    }
43
44
    protected function getExampleContent(int $id): APIContent
45
    {
46
        return new Content([
47
            'versionInfo' => new VersionInfo([
48
                'contentInfo' => $this->getExampleContentInfo($id),
49
            ]),
50
        ]);
51
    }
52
53
    protected function getExampleContentInfo(int $id): ContentInfo
54
    {
55
        return new ContentInfo([
56
            'id' => $id,
57
        ]);
58
    }
59
60
    protected function getExampleLocation(int $id): APILocation
61
    {
62
        return new Location(['id' => $id]);
63
    }
64
65
    protected function getExampleRouteReference($name, array $parameters = []): RouteReference
66
    {
67
        return new RouteReference($name, $parameters);
68
    }
69
70
    private function getRouteReferenceGenerator(): RouteReferenceGeneratorInterface
71
    {
72
        $generator = new RouteReferenceGenerator(
73
            $this->createMock(EventDispatcherInterface::class)
74
        );
75
        $request = new Request();
76
        $requestStack = new RequestStack();
77
        $requestStack->push($request);
78
        $generator->setRequestStack($requestStack);
79
80
        return $generator;
81
    }
82
83
    private function getUrlGenerator(): UrlGeneratorInterface
84
    {
85
        $generator = $this->createMock(UrlGeneratorInterface::class);
86
        $generator
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
            ->method('generate')
88
            ->willReturnCallback(static function ($name, $parameters, $referenceType): string {
89
                return json_encode([
90
                    '$name' => $name,
91
                    '$parameters' => $parameters,
92
                    '$referenceType' => $referenceType,
93
                ]);
94
            });
95
96
        return $generator;
97
    }
98
}
99