Skip to content

Commit

Permalink
Ensure scope are resolved correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Nov 11, 2024
1 parent 47b1029 commit 21a2b35
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Drivers/Decorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ public function instance($name)
*/
public function definedFeaturesForScope($scope)
{
$scope = $this->resolveScope($scope);

if ($this->driver instanceof DefinesFeaturesExternally) {
return collect($this->driver->definedFeaturesForScope($scope));
}
Expand Down
33 changes: 33 additions & 0 deletions tests/Feature/DefinesFeaturesExternallyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Config;
use Laravel\Pennant\Contracts\DefinesFeaturesExternally;
use Laravel\Pennant\Contracts\FeatureScopeable;
use Laravel\Pennant\Drivers\ArrayDriver;
use Laravel\Pennant\Feature;
use Tests\TestCase;
Expand Down Expand Up @@ -37,4 +38,36 @@ public function definedFeaturesForScope(mixed $scope): array
'feature-2' => false,
], $features);
}

public function test_when_features_are_defined_externally_that_scope_is_correctly_resolved()
{
$driver = new class(app('events'), []) extends ArrayDriver implements DefinesFeaturesExternally
{
/**
* Retrieve the defined features for the given scope.
*
* @return list<string>
*/
public function definedFeaturesForScope(mixed $scope): array
{
return [
$scope,
];
}
};
Feature::extend('external', fn () => $driver);
Config::set('pennant.stores.external', ['driver' => 'external']);

$features = Feature::driver('external')->for(new class implements FeatureScopeable
{
public function toFeatureIdentifier(string $driver): mixed
{
return 'scope-value';
}
})->all();

$this->assertSame([
'scope-value' => false,
], $features);
}
}

0 comments on commit 21a2b35

Please sign in to comment.