Skip to content

Commit

Permalink
Add loadAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Jul 18, 2024
1 parent 26bcd0a commit ac68d50
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/PendingScopedFeatureInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ public function loadMissing($features)
->pipe(fn ($features) => $this->driver->getAllMissing($features->all()));
}

/**
* Load all defined features into memory.
*
* @param string|array<int, string> $features
* @return array<string, array<int, mixed>>
*/
public function loadAll()
{
return $this->load($this->driver->defined());
}

/**
* Get the value of the flag.
*
Expand Down
31 changes: 31 additions & 0 deletions tests/Feature/DatabaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,37 @@ public function test_it_keys_by_feature_name()
FeatureWithoutName::class,
]));
}

public function testItCanLoadAllFeaturesForScope()
{
Feature::define('bar', fn ($scope) => $scope === 'taylor');
Feature::define('foo', fn ($scope) => $scope === 'tim');

Feature::for(['tim', 'taylor'])->loadAll();

$records = DB::table('features')->orderBy('scope')->orderBy('name')->get(['name', 'scope', 'value'])->all();
$this->assertCount(4, $records);
$this->assertEquals(literal(
scope: 'taylor',
value: 'true',
name: 'bar',
), $records[0]);
$this->assertEquals(literal(
scope: 'taylor',
value: 'false',
name: 'foo',
), $records[1]);
$this->assertEquals(literal(
scope: 'tim',
value: 'false',
name: 'bar',
), $records[2]);
$this->assertEquals(literal(
scope: 'tim',
value: 'true',
name: 'foo',
), $records[3]);
}
}

class UnregisteredFeature
Expand Down

0 comments on commit ac68d50

Please sign in to comment.