Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use response factory #13

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on: [push, pull_request]

jobs:
phpunit:
runs-on: ubuntu-latest
strategy:
matrix:
php: [7.1, 7.2, 7.3, 7.4]
steps:
- uses: actions/checkout@v1
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Validate Composer files
run: composer validate --no-check-all --strict
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run tests
run: php vendor/bin/phpunit
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
}
},
"require": {
"php": "^7.1",
"filp/whoops": "^1.1 || ^2.0",
"zendframework/zend-diactoros": "^1.1.0 || ^2.0"
"middlewares/utils": "^2.0 || ^3.0"
},
"suggest": {
"psr/http-server-middleware": "In case you want to use PSR 15 middleware"
Expand All @@ -20,7 +21,8 @@
}
},
"require-dev": {
"phpunit/phpunit": "7.0.*",
"psr/http-server-middleware": "^1.0"
"phpunit/phpunit": "^7.0",
"psr/http-server-middleware": "^1.0",
"laminas/laminas-diactoros": "^1.1.0 || ^2.0"
}
}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true"
>
<testsuites>
Expand Down
12 changes: 5 additions & 7 deletions src/WhoopsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Franzl\Middleware\Whoops;

use Middlewares\Utils\Factory;
use Psr\Http\Message\ServerRequestInterface;
use Whoops\Handler\PlainTextHandler;
use Whoops\Run;
use Zend\Diactoros\Response\HtmlResponse;

class WhoopsRunner
{
Expand All @@ -21,13 +21,11 @@ public static function handle($error, ServerRequestInterface $request)

ob_start();
$whoops->$method($error);
$response = ob_get_clean();
$content = ob_get_clean();

return new HtmlResponse(
$response,
500,
['Content-Type' => $format->getPreferredContentType()]
);
return Factory::createResponse(500)
->withBody(Factory::createStream($content))
->withHeader('Content-Type', $format->getPreferredContentType());
}

private static function getWhoopsInstance(Formats\Format $format)
Expand Down
4 changes: 2 additions & 2 deletions tests/WhoopsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Exception;
use Franzl\Middleware\Whoops\WhoopsMiddleware;
use Laminas\Diactoros\Response\TextResponse;
use Laminas\Diactoros\ServerRequest;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\TextResponse;
use Zend\Diactoros\ServerRequest;

class WhoopsMiddlewareTest extends TestCase
{
Expand Down