Skip to content

Commit

Permalink
Add tests for Sentry\Config
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Mar 12, 2024
1 parent 94a38cd commit 01b12bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Sentry/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function __construct(
public function toArray(): array
{
return [
'dsn' => $this->dsn,
'environment' => $this->environment,
'release' => $this->release,
'traces_sample_rate' => $this->traces_sample_rate,
'dsn' => $this->dsn,
'environment' => $this->environment,
'release' => $this->release,
'traces_sample_rate' => $this->traces_sample_rate,
'profiles_sample_rate' => $this->profiles_sample_rate,
];
}
Expand Down
42 changes: 42 additions & 0 deletions tests/Sentry/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Studiometa\WPToolkitTest;

use PHPUnit\Framework\TestCase;
use Studiometa\WPToolkit\Sentry\Config;

class ConfigTest extends TestCase {
public $values =[
'dsn' => 'dsn',
'js_loader_script' => 'js_loader_script',
'environment' => 'environment',
'release' => 'release',
'traces_sample_rate' => 0.0,
'profiles_sample_rate' => 0.0,
];

public function config() {
return new Config(
dsn: $this->values['dsn'],
js_loader_script: $this->values['js_loader_script'],
environment: $this->values['environment'],
release: $this->values['release'],
traces_sample_rate: $this->values['traces_sample_rate'],
profiles_sample_rate: $this->values['profiles_sample_rate'],
);
}

public function test_it_has_a_working_to_array_method() {
$expected = $this->values;
unset($expected['js_loader_script']);
$this->assertEqualsCanonicalizing($expected, $this->config()->toArray());
}

public function test_it_has_a_js_config_method() {
$expected = $this->values;
unset($expected['js_loader_script']);
unset($expected['dsn']);
$js_config = json_decode($this->config()->getJsConfig(), true);
$this->assertEqualsCanonicalizing($expected, $js_config);
}
}

0 comments on commit 01b12bc

Please sign in to comment.