From 01b12bc7ac34838e6198b591acb68b38eb24a9e9 Mon Sep 17 00:00:00 2001 From: Titouan Mathis Date: Tue, 12 Mar 2024 17:47:55 +0100 Subject: [PATCH] Add tests for Sentry\Config --- src/Sentry/Config.php | 8 +++---- tests/Sentry/ConfigTest.php | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 tests/Sentry/ConfigTest.php diff --git a/src/Sentry/Config.php b/src/Sentry/Config.php index d91e74f..6e92f21 100644 --- a/src/Sentry/Config.php +++ b/src/Sentry/Config.php @@ -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, ]; } diff --git a/tests/Sentry/ConfigTest.php b/tests/Sentry/ConfigTest.php new file mode 100644 index 0000000..c3afa44 --- /dev/null +++ b/tests/Sentry/ConfigTest.php @@ -0,0 +1,42 @@ + '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); + } +}