Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
debugging part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
k911 committed May 10, 2021
1 parent 734881c commit b3a7bd4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN pecl install xdebug && \

FROM ext-builder as ext-swoole
RUN apk add --no-cache git
ARG SWOOLE_VERSION="4.5.11"
ARG SWOOLE_VERSION="4.6.5"
RUN if $(echo "$SWOOLE_VERSION" | grep -qE '^[4-9]\.[0-9]+\.[0-9]+$'); then SWOOLE_GIT_REF="v$SWOOLE_VERSION"; else SWOOLE_GIT_REF="$SWOOLE_VERSION"; fi && \
git clone https://github.com/swoole/swoole-src.git --branch "$SWOOLE_GIT_REF" --depth 1 && \
cd swoole-src && \
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ x-env-aliases:
PHP_TAG: "${PHP_VERSION:-7.4}-cli-alpine${ALPINE_VERSION:-3.13}"
PHP_API_VERSION: "${PHP_API_VERSION:-20190902}"
COMPOSER_ARGS: "${COMPOSER_ARGS:-install}"
SWOOLE_VERSION: "${SWOOLE_VERSION:-4.5.11}"
SWOOLE_VERSION: "${SWOOLE_VERSION:-4.6.5}"
COMPOSER_TAG: "${COMPOSER_TAG:-2.0.11}"

volumes:
Expand Down
34 changes: 17 additions & 17 deletions src/Bridge/Symfony/HttpKernel/DebugHttpKernelRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ public function __construct(RequestHandlerInterface $decorated, KernelInterface
*/
public function handle(Request $request, Response $response): void
{
if ($this->kernel->isDebug()) {
replace_object_property($this->kernel, 'startTime', \microtime(true));
}
// if ($this->kernel->isDebug()) {
// replace_object_property($this->kernel, 'startTime', \microtime(true));
// }

$this->decorated->handle($request, $response);

if ($this->kernel->isDebug()) {
if ($this->container->has('debug.stopwatch')) {
/** @var Stopwatch $stopwatch */
$stopwatch = $this->container->get('debug.stopwatch');
$stopwatch->reset();
}

if ($this->container->has('profiler')) {
/** @var Profiler $profiler */
$profiler = $this->container->get('profiler');
$profiler->reset();
$profiler->enable();
}
}
// if ($this->kernel->isDebug()) {
// if ($this->container->has('debug.stopwatch')) {
// /** @var Stopwatch $stopwatch */
// $stopwatch = $this->container->get('debug.stopwatch');
// $stopwatch->reset();
// }
//
// if ($this->container->has('profiler')) {
// /** @var Profiler $profiler */
// $profiler = $this->container->get('profiler');
// $profiler->reset();
// $profiler->enable();
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public function handle(Request $request, Throwable $exception, Response $respons
{
$data = $this->exceptionArrayTransformer->transform($exception, $this->verbosity);

if (\method_exists($response, 'isWritable') && !$response->isWritable()) {
echo 'Response is not writable'.\PHP_EOL;

return;
}
$response->header(Http::HEADER_CONTENT_TYPE, Http::CONTENT_TYPE_APPLICATION_JSON);
$response->status(500);
$response->end(\json_encode($data, \JSON_THROW_ON_ERROR));
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/SwooleServerStaticFilesServingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public function testAdvancedStaticFilesServerWithAutoRegistration(): void
'--port=9999',
], ['APP_ENV' => 'auto']);

$serverRun->setTimeout(10);
$serverRun->setTimeout(self::coverageEnabled() ? 10 : 5);
$serverRun->start();

$this->runAsCoroutineAndWait(function (): void {
$client = HttpClient::fromDomain('localhost', 9999, false);
$this->assertTrue($client->connect());
$this->assertHelloWorldRequestSucceeded($client);

$response = $client->send('/robots.txt')['response'];

Expand Down
8 changes: 6 additions & 2 deletions tests/Feature/SymfonyProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use K911\Swoole\Client\HttpClient;
use K911\Swoole\Tests\Fixtures\Symfony\TestBundle\Test\ServerTestCase;
use Swoole\Coroutine;

final class SymfonyProfilerTest extends ServerTestCase
{
Expand All @@ -16,27 +17,30 @@ protected function setUp(): void
$this->markTestSkippedIfXdebugEnabled();
}

public function testAdvancedStaticFilesServerWithAutoRegistration(): void
public function testSymfonyProfilerTwigDebugLink(): void
{
$serverRun = $this->createConsoleProcess([
'swoole:server:run',
'--host=localhost',
'--port=9999',
], ['APP_ENV' => 'profiler']);

$serverRun->setTimeout(10);
$serverRun->setTimeout(self::coverageEnabled() ? 10 : 5);
$serverRun->start();

$this->runAsCoroutineAndWait(function (): void {
$client = HttpClient::fromDomain('localhost', 9999, false);
$this->assertTrue($client->connect());
$this->assertHelloWorldRequestSucceeded($client);

$response = $client->send('/twig')['response'];

$this->assertSame(200, $response['statusCode']);
$this->assertNotEmpty($response['headers']['x-debug-token']);
$debugToken = $response['headers']['x-debug-token'];

Coroutine::sleep(2);

$client2 = HttpClient::fromDomain('localhost', 9999, false);
$this->assertTrue($client2->connect());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace K911\Swoole\Tests\Fixtures\Symfony\CoverageBundle\RequestHandler;

use function K911\Swoole\get_object_property;
use K911\Swoole\Server\RequestHandler\RequestHandlerInterface;
use K911\Swoole\Tests\Fixtures\Symfony\CoverageBundle\Coverage\CodeCoverageManager;
use Swoole\Http\Request;
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixtures/Symfony/app/config/profiler/swoole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
swoole:
http_server:
exception_handler:
type: symfony

0 comments on commit b3a7bd4

Please sign in to comment.