Skip to content

Commit

Permalink
Add Options::setDsn()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 committed Dec 13, 2018
1 parent b9e9e4b commit 0715cc7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Options
/**
* @var array The configuration options
*/
private $options = [];
private $options;

/**
* @var string|null A simple server string, set to the DSN found on your Sentry settings
Expand Down Expand Up @@ -393,6 +393,18 @@ public function getDsn(): ?string
return $this->dsn;
}

/**
* Sets the DSN of the Sentry server the authenticated user is bound to.
*
* @param string $dsn
*/
public function setDsn(string $dsn): void
{
$options = array_merge($this->options, ['dsn' => $dsn]);

$this->options = $this->resolver->resolve($options);
}

/**
* Gets the name of the server the SDK is running on (e.g. the hostname).
*
Expand Down
16 changes: 15 additions & 1 deletion tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class OptionsTest extends TestCase
/**
* @dataProvider optionsDataProvider
*/
public function testConstructor($option, $value, $getterMethod): void
public function testConstructor(string $option, $value, string $getterMethod): void
{
$configuration = new Options([$option => $value]);

Expand Down Expand Up @@ -73,6 +73,20 @@ public function testServerOption(string $dsn, array $options): void
$this->assertEquals($options['server'], $configuration->getDsn());
}

/**
* @dataProvider serverOptionDataProvider
*/
public function testServerOptionUsingTheSetter(string $dsn, array $options): void
{
$configuration = new Options();
$configuration->setDsn($dsn);

$this->assertEquals($options['project_id'], $configuration->getProjectId());
$this->assertEquals($options['public_key'], $configuration->getPublicKey());
$this->assertEquals($options['secret_key'], $configuration->getSecretKey());
$this->assertEquals($options['server'], $configuration->getDsn());
}

public function serverOptionDataProvider(): array
{
return [
Expand Down

0 comments on commit 0715cc7

Please sign in to comment.