|
| 1 | +<?php |
| 2 | +namespace GT\WebEngine\Test\Dispatch; |
| 3 | + |
| 4 | +use Gt\Config\Config; |
| 5 | +use Gt\Http\Request; |
| 6 | +use Gt\Http\ResponseStatusException\ClientError\HttpNotFound; |
| 7 | +use Gt\Http\Uri; |
| 8 | +use Gt\Session\FileHandler; |
| 9 | +use GT\WebEngine\Dispatch\DispatcherFactory; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class DispatcherFactoryTest extends TestCase { |
| 13 | + public function testCreate():void { |
| 14 | + $config = self::createMock(Config::class); |
| 15 | + $config->method("getString") |
| 16 | + ->willReturnMap([ |
| 17 | + ["app.namespace", "Example\\NS"], |
| 18 | + ["app.class_dir", "/tmp/phpgt-webengine-test--dispatcher-factory--class"], |
| 19 | + ["router.router_file", "/tmp/phpgt-webengine-test--dispatcher-factory--router"], |
| 20 | + ["router.router_class", "TestRouter"], |
| 21 | + ["router.default_content_type", "unit/test"], |
| 22 | + ["session.name", "GT_Test_Session"], |
| 23 | + ["session.handler", FileHandler::class], |
| 24 | + ["session.path", "/"], |
| 25 | + ["view.component_directory", "/tmp/phpgt-webengine-test--dispatcher-factory--component-dir"], |
| 26 | + ["view.partial_directory", "/tmp/phpgt-webengine-test--dispatcher-factory--partial-dir"], |
| 27 | + ]); |
| 28 | + $config->method("getInt") |
| 29 | + ->willReturnMap([ |
| 30 | + ["router.redirect_response_code", 321], |
| 31 | + ]); |
| 32 | + |
| 33 | + $requestUri = self::createMock(Uri::class); |
| 34 | + $requestUri->method("getPath") |
| 35 | + ->willReturn("/test/"); |
| 36 | + $request = self::createMock(Request::class); |
| 37 | + $request->method("getUri") |
| 38 | + ->willReturn($requestUri); |
| 39 | + $request->method("getMethod") |
| 40 | + ->willReturn("GET"); |
| 41 | + $globals = [ |
| 42 | + "_GET" => [], |
| 43 | + "_POST" => [], |
| 44 | + "_FILES" => [], |
| 45 | + "_SERVER" => [], |
| 46 | + "_COOKIE" => [], |
| 47 | + ]; |
| 48 | + $finishCallback = fn() => null; |
| 49 | + $errorStatus = 123; |
| 50 | + |
| 51 | + $sut = new DispatcherFactory(); |
| 52 | + $dispatcher = $sut->create($config, $request, $globals, $finishCallback, $errorStatus); |
| 53 | + self::expectException(HttpNotFound::class); |
| 54 | + $dispatcher->generateResponse(); |
| 55 | + } |
| 56 | +} |
0 commit comments