Skip to content

Commit

Permalink
Simplify internal feature mocking to remove array support
Browse files Browse the repository at this point in the history
We don't use this anywhere but a test, so no reason to have it. It also lets us remove the null type.
  • Loading branch information
caendesilva committed Apr 11, 2024
1 parent 56c0b94 commit 3ae0e24
Showing 2 changed files with 5 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
use Hyde\Enums\Feature;
use Illuminate\Support\Str;

use function is_array;

/**
* Allows the Features class to be mocked.
*
@@ -20,16 +18,8 @@ trait MockableFeatures
{
protected static array $mockedInstances = [];

public static function mock(string|array $feature, ?bool $enabled = null): void
public static function mock(string $feature, bool $enabled): void
{
if (is_array($feature)) {
foreach ($feature as $key => $value) {
static::mock($key, $value);
}

return;
}

static::$mockedInstances[Str::studly($feature)] = $enabled;
}

12 changes: 4 additions & 8 deletions packages/framework/tests/Feature/ConfigurableFeaturesTest.php
Original file line number Diff line number Diff line change
@@ -106,18 +106,14 @@ public function testDynamicFeaturesCanBeMocked()

public function testMultipleFeaturesCanBeMocked()
{
Features::mock([
'rss' => true,
'darkmode' => true,
]);
Features::mock('rss', true);
Features::mock('darkmode', true);

$this->assertTrue(Features::rss());
$this->assertTrue(Features::hasDarkmode());

Features::mock([
'rss' => false,
'darkmode' => false,
]);
Features::mock('rss', false);
Features::mock('darkmode', false);

$this->assertFalse(Features::rss());
$this->assertFalse(Features::hasDarkmode());

0 comments on commit 3ae0e24

Please sign in to comment.