Skip to content

Commit

Permalink
Updated react and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slischka committed May 2, 2021
1 parent 0609eb5 commit 43d3af4
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"nette/di": "^3.0",
"phpstan/phpstan": "^0.12.85",
"phpstan/phpstan-nette": "^0.12.17",
"react/http": "^0.8.3",
"react/child-process": "^0.5.2",
"react/http": "^1.3",
"react/child-process": "^0.6.2",
"phpstan/phpstan-strict-rules": "^0.12.9",
"orisai/coding-standard": "^1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Fapi/HttpClient/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HttpRequest extends Request
/**
* @param UriInterface|string $uri
* @param array<mixed> $headers
* @param \Psr\Http\Message\StreamInterface|string|null $body
* @param StreamInterface|string|null $body
*/
public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
{
Expand Down
3 changes: 2 additions & 1 deletion src/Fapi/HttpClient/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Fapi\HttpClient;

use GuzzleHttp\Psr7\Response;
use Psr\Http\Message\StreamInterface;
use function is_array;
use function is_string;

Expand All @@ -11,7 +12,7 @@ class HttpResponse extends Response

/**
* @param array<mixed> $headers
* @param \Psr\Http\Message\StreamInterface|string|null $body
* @param StreamInterface|string|null $body
*/
public function __construct(
int $status = 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Psr\Http\Message\ServerRequestInterface;
use React;
use React\Http\Message\Response;
use function assert;
use function base64_encode;
use function is_array;
Expand All @@ -14,7 +15,7 @@
class ApiRequestHandler
{

public function handleRequest(ServerRequestInterface $request): React\Http\Response
public function handleRequest(ServerRequestInterface $request): React\Http\Message\Response
{
$method = $request->getMethod();
$headers = $request->getHeaders();
Expand Down Expand Up @@ -55,7 +56,7 @@ public function handleRequest(ServerRequestInterface $request): React\Http\Respo
throw new InvalidHttpRequestException('Response body is not valid. ' . json_encode($data));
}

return new React\Http\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
return new Response(200, ['Content-Type' => 'text/plain'], "OK\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AssignCookieRequestHandler

public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
return new React\Http\Response(200, [
return new React\Http\Message\Response(200, [
'Content-Type' => 'text/plain',
'Set-Cookie' => 'sample-name=sample-value; path=/',
], "OK\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
throw new InvalidHttpRequestException('Header Cookie has an unexpected value.');
}

return new React\Http\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
return new React\Http\Message\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
{
sleep(2);

return new React\Http\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
return new React\Http\Message\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class EmptyRequestHandler

public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
return new React\Http\Response(200, ['Content-Type' => 'text/plain'], '');
return new React\Http\Message\Response(200, ['Content-Type' => 'text/plain'], '');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handleRequest(
throw new InvalidHttpRequestException('Response body is not valid.');
}

return new React\Http\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
return new React\Http\Message\Response(200, ['Content-Type' => 'text/plain'], "OK\n");
}

}
4 changes: 2 additions & 2 deletions tests/Fapi/HttpClientTests/MockHttpServer/MockHttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use React;
use React\Http\Response;
use React\Http\Message\Response;
use function fflush;
use function fwrite;
use const STDOUT;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function run(): void
{
$this->eventLoop = React\EventLoop\Factory::create();
$this->socketServer = new React\Socket\Server('1337', $this->eventLoop);
$this->httpServer = new React\Http\Server([$this, 'handleRequest']);
$this->httpServer = new React\Http\Server($this->eventLoop, [$this, 'handleRequest']);

$this->apiRequestHandler = new ApiRequestHandler();
$this->assignCookieRequestHandler = new AssignCookieRequestHandler();
Expand Down
1 change: 1 addition & 0 deletions tools/cs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>

<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion.RequiredExplicitAssertion"/>
</rule>

<!-- Configure PSR-4 rule -->
Expand Down

0 comments on commit 43d3af4

Please sign in to comment.