Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 706ef48

Browse filesBrowse files
committed
Added tests
1 parent d42ffc6 commit 706ef48
Copy full SHA for 706ef48

File tree

7 files changed

+74
-11
lines changed
Filter options

7 files changed

+74
-11
lines changed

‎src/Symfony/Component/Runtime/PsrRuntime.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Runtime/PsrRuntime.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PsrRuntime extends GenericRuntime
4242
* psr17_uri_factory?: ?string,
4343
* psr17_uploaded_file_factory?: ?string,
4444
* psr17_stream_factory?: ?string,
45+
* laminas_emitter?: ?string,
4546
* } $options
4647
*/
4748
public function __construct(array $options = [])
@@ -54,11 +55,11 @@ public function __construct(array $options = [])
5455
public function getRunner(?object $application): RunnerInterface
5556
{
5657
if ($application instanceof RequestHandlerInterface) {
57-
return LaminasEmitter::createForRequestHandler($application, $this->createRequest());
58+
return LaminasEmitter::createForRequestHandler($application, $this->createRequest(), ['emitter'=>$this->options['laminas_emitter'] ?? null]);
5859
}
5960

6061
if ($application instanceof ResponseInterface) {
61-
return LaminasEmitter::createForResponse($application);
62+
return LaminasEmitter::createForResponse($application, ['emitter'=>$this->options['laminas_emitter'] ?? null]);
6263
}
6364

6465
return parent::getRunner($application);

‎src/Symfony/Component/Runtime/Runner/Psr/LaminasEmitter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Runtime/Runner/Psr/LaminasEmitter.php
+15-8Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,33 @@ class LaminasEmitter implements RunnerInterface
2929
private $request;
3030
private $emitter;
3131

32-
private function __construct()
32+
private function __construct(array $options)
3333
{
34-
if (!class_exists(SapiEmitter::class)) {
35-
throw new \LogicException(sprintf('The "%s" class requires "laminas/laminas-httphandlerrunner". Try running "composer require laminas/laminas-httphandlerrunner".', self::class));
34+
$class = $options['emitter'] ?? SapiEmitter::class;
35+
if (!class_exists($class)) {
36+
throw new \LogicException(sprintf('The class "%s" cannot be found. Try running "composer require laminas/laminas-httphandlerrunner".', $class));
3637
}
3738

38-
$this->emitter = new SapiEmitter();
39+
$this->emitter = new $class();
3940
}
4041

41-
public static function createForResponse(ResponseInterface $response): self
42+
/**
43+
* @param array{emitter?: ?string} $options
44+
*/
45+
public static function createForResponse(ResponseInterface $response, array $options): self
4246
{
43-
$emitter = new self();
47+
$emitter = new self($options);
4448
$emitter->response = $response;
4549

4650
return $emitter;
4751
}
4852

49-
public static function createForRequestHandler(RequestHandlerInterface $handler, ServerRequestInterface $request): self
53+
/**
54+
* @param array{emitter?: ?string} $options
55+
*/
56+
public static function createForRequestHandler(RequestHandlerInterface $handler, ServerRequestInterface $request, array $options): self
5057
{
51-
$emitter = new self();
58+
$emitter = new self($options);
5259
$emitter->requestHandler = $handler;
5360
$emitter->request = $request;
5461

‎src/Symfony/Component/Runtime/Tests/phpt/autoload.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Runtime/Tests/phpt/autoload.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
}
1313

1414
$app = require $_SERVER['SCRIPT_FILENAME'];
15-
$runtime = new SymfonyRuntime($_SERVER['APP_RUNTIME_OPTIONS']);
15+
$runtimeClass = $_SERVER['APP_RUNTIME'] ?? SymfonyRuntime::class;
16+
$runtime = new $runtimeClass($_SERVER['APP_RUNTIME_OPTIONS']);
1617
[$app, $args] = $runtime->getResolver($app)->resolve();
1718
exit($runtime->getRunner($app(...$args))->run());
1819
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use Psr\Http\Server\RequestHandlerInterface;
4+
use Psr\Http\Message\ServerRequestInterface;
5+
use Psr\Http\Message\ResponseInterface;
6+
7+
$_SERVER['APP_RUNTIME'] = \Symfony\Component\Runtime\PsrRuntime::class;
8+
9+
require __DIR__.'/autoload.php';
10+
11+
return function (array $context) {
12+
return new class implements RequestHandlerInterface {
13+
public function handle(ServerRequestInterface $request): ResponseInterface
14+
{
15+
return new \Nyholm\Psr7\Response(200, [], 'Hello PSR-15');
16+
}
17+
};
18+
};
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Test PSR-15 Request/Response
3+
--INI--
4+
display_errors=1
5+
--FILE--
6+
<?php
7+
8+
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/psr15.php';
9+
10+
?>
11+
--EXPECTF--
12+
Hello PSR-15
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Request;
4+
use Symfony\Component\HttpFoundation\Response;
5+
6+
$_SERVER['APP_RUNTIME'] = \Symfony\Component\Runtime\PsrRuntime::class;
7+
8+
require __DIR__.'/autoload.php';
9+
10+
return function (\Psr\Http\Message\ServerRequestInterface $request) {
11+
return new \Nyholm\Psr7\Response(200, [], 'Hello PSR-7');
12+
};
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Test PSR-7 Request/Response
3+
--INI--
4+
display_errors=1
5+
--FILE--
6+
<?php
7+
8+
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/psr7.php';
9+
10+
?>
11+
--EXPECTF--
12+
Hello PSR-7

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.