Skip to content

Commit 5a50a95

Browse files
committed
Add tests
1 parent 2e892f1 commit 5a50a95

File tree

2 files changed

+107
-4
lines changed

2 files changed

+107
-4
lines changed

src/Sentry/Laravel/Features/PennantPackageIntegration.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public function onBoot(Dispatcher $events): void
2525

2626
public function handleFeatureRetrieved($feature): void
2727
{
28-
if (!is_bool($feature->value)) {
29-
return; // rich features are not supported yet
30-
}
31-
3228
SentrySdk::getCurrentHub()->configureScope(function (Scope $scope) use ($feature) {
3329
// The value of the feature is not always a bool (Rich Feature Values) but only bools are supported.
3430
// The feature is considered "active" if its value is not explicitly false following Pennant's logic.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Sentry\Laravel\Tests\Features;
4+
5+
use Laravel\Folio\Folio;
6+
use Laravel\Pennant\Feature;
7+
use Sentry\Event;
8+
use Sentry\EventType;
9+
use Sentry\Laravel\Integration;
10+
use Illuminate\Config\Repository;
11+
use Sentry\Laravel\Tests\TestCase;
12+
use Illuminate\Database\Eloquent\Model;
13+
14+
class PennantPackageIntegrationTest extends TestCase
15+
{
16+
protected function setUp(): void
17+
{
18+
if (!class_exists(Feature::class)) {
19+
$this->markTestSkipped('Laravel Pennant package is not installed.');
20+
}
21+
22+
parent::setUp();
23+
}
24+
25+
protected function defineEnvironment($app): void
26+
{
27+
parent::defineEnvironment($app);
28+
29+
tap($app['config'], static function (Repository $config) {
30+
// Force Pennant to use the array driver instead of the database which is the default
31+
$config->set('pennant.default', 'array');
32+
$config->set('pennant.stores.array', ['driver' => 'array']);
33+
});
34+
}
35+
36+
public function testPennantFeatureIsRecorded(): void
37+
{
38+
Feature::define('new-dashboard', static function () {
39+
return true;
40+
});
41+
42+
Feature::active('new-dashboard');
43+
44+
$scope = $this->getCurrentSentryScope();
45+
46+
$event = $scope->applyToEvent(Event::createEvent());
47+
48+
$this->assertArrayHasKey('flags', $event->getContexts());
49+
50+
$flags = $event->getContexts()['flags']['values'];
51+
52+
$this->assertEquals([
53+
[
54+
'flag' => 'new-dashboard',
55+
'result' => true,
56+
]
57+
], $flags);
58+
}
59+
60+
public function testPennantRichFeatureIsRecordedAsActive(): void
61+
{
62+
Feature::define('dashboard-version', static function () {
63+
return 'dark';
64+
});
65+
66+
Feature::value('dashboard-version');
67+
68+
$scope = $this->getCurrentSentryScope();
69+
70+
$event = $scope->applyToEvent(Event::createEvent());
71+
72+
$this->assertArrayHasKey('flags', $event->getContexts());
73+
74+
$flags = $event->getContexts()['flags']['values'];
75+
76+
$this->assertEquals([
77+
[
78+
'flag' => 'dashboard-version',
79+
'result' => true,
80+
]
81+
], $flags);
82+
}
83+
84+
public function testPennantRichFeatureIsRecordedAsInactive(): void
85+
{
86+
Feature::define('dashboard-version', static function () {
87+
return false;
88+
});
89+
90+
Feature::value('dashboard-version');
91+
92+
$scope = $this->getCurrentSentryScope();
93+
94+
$event = $scope->applyToEvent(Event::createEvent());
95+
96+
$this->assertArrayHasKey('flags', $event->getContexts());
97+
98+
$flags = $event->getContexts()['flags']['values'];
99+
100+
$this->assertEquals([
101+
[
102+
'flag' => 'dashboard-version',
103+
'result' => false,
104+
]
105+
], $flags);
106+
}
107+
}

0 commit comments

Comments
 (0)