Skip to content

Commit 2fdd8ff

Browse files
committed
Added RouteExtension tests
Signed-off-by: alexmerlin <[email protected]>
1 parent 556f837 commit 2fdd8ff

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AdminTest\Unit\App\Twig\Extension;
6+
7+
use Admin\App\Twig\Extension\RouteExtension;
8+
use AdminTest\Unit\UnitTest;
9+
use Laminas\Diactoros\ServerRequest;
10+
use Laminas\Diactoros\Uri;
11+
use Mezzio\Helper\UrlHelper;
12+
use Mezzio\Router\RouterInterface;
13+
use PHPUnit\Framework\MockObject\Exception;
14+
use Twig\TwigFunction;
15+
16+
use function method_exists;
17+
18+
class RouteExtensionTest extends UnitTest
19+
{
20+
/**
21+
* @throws Exception
22+
*/
23+
public function testWillInstantiate(): void
24+
{
25+
$urlHelper = $this->createMock(UrlHelper::class);
26+
$routeExtension = new RouteExtension($urlHelper);
27+
$this->assertInstanceOf(RouteExtension::class, $routeExtension);
28+
}
29+
30+
/**
31+
* @throws Exception
32+
*/
33+
public function testWillAddExistingFunctions(): void
34+
{
35+
$routeExtension = new RouteExtension(
36+
$this->createMock(UrlHelper::class)
37+
);
38+
39+
$functions = $routeExtension->getFunctions();
40+
$this->assertCount(1, $functions);
41+
42+
$twigFunction = $functions[0];
43+
$this->assertInstanceOf(TwigFunction::class, $twigFunction);
44+
45+
$callable = $twigFunction->getCallable();
46+
$this->assertIsArray($callable);
47+
$this->assertCount(2, $callable);
48+
$this->assertInstanceOf(RouteExtension::class, $callable[0]);
49+
$this->assertTrue(method_exists($routeExtension, $callable[1]));
50+
$this->assertSame($twigFunction->getName(), $callable[1]);
51+
}
52+
53+
/**
54+
* @throws Exception
55+
*/
56+
public function testWillGetCurrentRoute(): void
57+
{
58+
$router = $this->createMock(RouterInterface::class);
59+
$request = new ServerRequest(uri: new Uri('/test'));
60+
$urlHelper = new UrlHelper($router);
61+
$urlHelper->setRequest($request);
62+
$routeExtension = new RouteExtension($urlHelper);
63+
$this->assertSame('/test', $routeExtension->getCurrentRoute());
64+
}
65+
}

0 commit comments

Comments
 (0)