Skip to content

Commit

Permalink
Merge user_context by default
Browse files Browse the repository at this point in the history
Fixes GH-353
  • Loading branch information
dcramer committed Dec 9, 2016
1 parent 249b210 commit 8a5bff2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,15 @@ public function onShutdown()
* Sets user context.
*
* @param array $data Associative array of user data
* @param bool $merge Merge existing context with new context
*/
public function user_context($data)
public function user_context($data, $merge=true)
{
$this->context->user = $data;
if ($merge && $this->context->user !== null) {
$this->context->user = array_merge($this->context->user, $data);
} else {
$this->context->user = $data;
}
}

/**
Expand Down
18 changes: 18 additions & 0 deletions test/Raven/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,24 @@ public function testBuildCurlCommandEscapesInput()
$result = $client->buildCurlCommand('http:https://foo.com', $data, array());
$this->assertEquals($result, 'curl -X POST -d \'{"foo": "\'\\\'\'; ls;"}\' \'http:https://foo.com\' -m 5 > /dev/null 2>&1 &');
}

public function testUserContextWithoutMerge()
{
$client = new Dummy_Raven_Client();
$client->user_context(array('foo' => 'bar'), false);
$client->user_context(array('baz' => 'bar'), false);
$this->assertEquals($client->context->user, array('baz' => 'bar'));
}

public function testUserContextWithMerge()
{
$client = new Dummy_Raven_Client();
$client->user_context(array('foo' => 'bar'), true);
$client->user_context(array('baz' => 'bar'), true);
$this->assertEquals($client->context->user, array('foo' => 'bar', 'baz' => 'bar'));
}


/**
* Set the server array to the test values, check the current url
*
Expand Down

0 comments on commit 8a5bff2

Please sign in to comment.