|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace DotTest\Controller\Plugin; |
| 6 | + |
| 7 | +use Dot\Controller\Plugin\UrlHelperPlugin as Subject; |
| 8 | +use Mezzio\Helper\UrlHelper; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class UrlHelperPluginTest extends TestCase |
| 12 | +{ |
| 13 | + private UrlHelper $urlHelper; |
| 14 | + private Subject $subject; |
| 15 | + |
| 16 | + public function setUp(): void |
| 17 | + { |
| 18 | + $this->urlHelper = $this->createMock(UrlHelper::class); |
| 19 | + $this->subject = new Subject($this->urlHelper); |
| 20 | + } |
| 21 | + |
| 22 | + public function testInvokeWithoutArguments(): void |
| 23 | + { |
| 24 | + $result = $this->subject->__invoke(); |
| 25 | + |
| 26 | + $this->assertInstanceOf(Subject::class, $result); |
| 27 | + } |
| 28 | + |
| 29 | + public function testInvokeWithArguments(): void |
| 30 | + { |
| 31 | + $routeName = 'test.route'; |
| 32 | + $routeParams = ['id' => 123]; |
| 33 | + $queryParams = ['sort' => 'asc']; |
| 34 | + $fragmentIdentifier = 'section'; |
| 35 | + $options = ['absolute' => true]; |
| 36 | + |
| 37 | + $this->urlHelper->expects($this->once()) |
| 38 | + ->method('generate') |
| 39 | + ->with($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options) |
| 40 | + ->willReturn('http://example.com/test-route?id=123&sort=asc#section'); |
| 41 | + |
| 42 | + $result = $this->subject->__invoke($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options); |
| 43 | + |
| 44 | + $this->assertSame('http://example.com/test-route?id=123&sort=asc#section', $result); |
| 45 | + } |
| 46 | + |
| 47 | + public function testGenerate(): void |
| 48 | + { |
| 49 | + $routeName = 'test.route'; |
| 50 | + $routeParams = ['id' => 123]; |
| 51 | + $queryParams = ['sort' => 'asc']; |
| 52 | + $fragmentIdentifier = 'section'; |
| 53 | + $options = ['absolute' => true]; |
| 54 | + |
| 55 | + $this->urlHelper->expects($this->once()) |
| 56 | + ->method('generate') |
| 57 | + ->with($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options) |
| 58 | + ->willReturn('http://example.com/test-route?id=123&sort=asc#section'); |
| 59 | + |
| 60 | + $result = $this->subject->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options); |
| 61 | + |
| 62 | + $this->assertSame('http://example.com/test-route?id=123&sort=asc#section', $result); |
| 63 | + } |
| 64 | +} |
0 commit comments