Skip to content

Commit

Permalink
Allow serialization 5 levels deep (port of #554 to 2.x)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed May 4, 2018
1 parent 9ec6d84 commit da97fce
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function sanitize(Event $event)
$tagsContext = $event->getTagsContext();

if (!empty($request)) {
$event = $event->withRequest($this->serializer->serialize($request));
$event = $event->withRequest($this->serializer->serialize($request, 5));
}
if (!empty($userContext)) {
$event = $event->withUserContext($this->serializer->serialize($userContext, 3));
Expand Down
69 changes: 58 additions & 11 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,32 +503,79 @@ public function testSanitizeUser()
$this->assertEquals(['email' => 'foo@example.com'], $event->getUserContext());
}

public function testSanitizeRequest()
/**
* @dataProvider deepRequestProvider
*/
public function testSanitizeRequest(array $postData, array $expectedData)
{
$client = ClientBuilder::create()->getClient();

$event = new Event($client->getConfig());
$event = $event->withRequest([
'context' => [
'line' => 1216,
'stack' => [
1, [2], 3,
],
'method' => 'POST',
'url' => 'https://example.com/something',
'query_string' => '',
'data' => [
'_method' => 'POST',
'data' => $postData,
],
]);

$event = $client->sanitize($event);

$this->assertArraySubset([
'context' => [
'line' => 1216,
'stack' => [
1, 'Array of length 1', 3,
],
'method' => 'POST',
'url' => 'https://example.com/something',
'query_string' => '',
'data' => [
'_method' => 'POST',
'data' => $expectedData,
],
], $event->getRequest());
}

public function deepRequestProvider()
{
return [
[
[
'MyModel' => [
'flatField' => 'my value',
'nestedField' => [
'key' => 'my other value',
],
],
],
[
'MyModel' => [
'flatField' => 'my value',
'nestedField' => [
'key' => 'my other value',
],
],
]
],
[
[
'Level 1' => [
'Level 2' => [
'Level 3' => [
'Level 4' => 'something',
],
],
],
],
[
'Level 1' => [
'Level 2' => [
'Level 3' => 'Array of length 1',
],
],
],
],
];
}

private function assertMixedValueAndArray($expected_value, $actual_value)
{
if (null === $expected_value) {
Expand Down

0 comments on commit da97fce

Please sign in to comment.