Skip to content

Commit

Permalink
Not logging extreme long bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
mcustiel committed Jan 24, 2018
1 parent 98c151e commit 5c35acf
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/Domain/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function __construct($matcher = null, $value = null)
$this->value = $value;
}

public function __toString()
{
return $this->matcher . ' ' . var_export($this->value, true);
}

/**
* @return string
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Domain/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ class Expectation implements \JsonSerializable
*/
private $priority = 0;

public function __toString()
{
return print_r(
[
'scenarioName' => $this->scenarioName,
'scenarioStateIs' => $this->scenarioStateIs,
'newScenarioState' => $this->newScenarioState,
'request' => isset($this->request) ? $this->request->__toString() : 'null',
'response' => isset($this->response) ? $this->response->__toString() : 'null',
'proxyTo' => $this->proxyTo,
'priority' => $this->priority,
], true
);
}

/**
* @return \Mcustiel\Phiremock\Domain\Request
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Domain/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ class Request implements \JsonSerializable
*/
private $headers;

public function __toString()
{
return print_r(
[
'method' => $this->method,
'url' => isset($this->url) ? $this->url->__toString() : 'null',
'body' => isset($this->body) ? $this->body->getMatcher() . ' => ' . (isset($this->body->getValue()[5000]) ? '--VERY LONG CONTENTS--' : $this->body->getValue()) : 'null',
'headers' => print_r($this->headers, true),
],
true
);
}

/**
* @return string
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Domain/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ class Response implements \JsonSerializable
*/
private $delayMillis;

public function __toString()
{
return print_r(
[
'statusCode' => $this->statusCode,
'body' => isset($this->body[5000]) ? '--VERY LONG CONTENTS--' : $this->body,
'headers' => $this->headers,
'delayMillis' => $this->delayMillis,
],
true
);
}

/**
* @return int
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Actions/Base/AbstractRequestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function parseRequestObject(ServerRequestInterface $request)
Expectation::class,
RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION
);
$this->logger->debug('Parsed expectation: ' . var_export($object, true));
$this->logger->debug('Parsed expectation: ' . $object);

return $object;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Server/Actions/VerifyRequestFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public function execute(TransactionData $transactionData, $argument = null)
*/
private function getLoggableResponse(ResponseInterface $response)
{
$body = $response->getBody()->__toString();

return $response->getStatusCode() . ' / '
. preg_replace('|\s+|', ' ', $response->getBody()->__toString());
. strlen($body) > 5000 ? '--VERY LONG CONTENTS--' : preg_replace('|\s+|', ' ', $body);
}

/**
Expand Down
26 changes: 16 additions & 10 deletions tests/tests/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
// Here you can initialize variables that will be available to your tests

$expectationsDir = __DIR__ . '/../_data/expectations';
$command = 'exec php ' . APP_ROOT . 'bin/phiremock --port 8086 -e ' . $expectationsDir;
echo 'Running ' . $command . PHP_EOL;
$command = [
'php',
APP_ROOT . 'bin/phiremock',
'--port',
'8086',
'-d',
'-e',
$expectationsDir,
'>',
codecept_log_dir() . '/phiremock.log',
'2>&1',
]; /*
echo 'Running ' . implode(' ', $command) . PHP_EOL;
$process = new Process($command);

$process->disableOutput();
register_shutdown_function(function () use ($process) {
echo 'Terminating phiremock' . PHP_EOL;
$process->stop(10, defined('SIGTERM') ? SIGTERM : null);
});
$process->start(function ($type, $buffer) {
if (Process::ERR === $type) {
echo 'ERR > ' . $buffer;
} else {
echo 'OUT > ' . $buffer;
}
});
$process->start();
*/
sleep(1);

0 comments on commit 5c35acf

Please sign in to comment.