Skip to content

Commit

Permalink
[1.x] Added "all" method to "EnsureFeaturesAreActive" middleware. (#70)
Browse files Browse the repository at this point in the history
* Added "all" method to "EnsureFeaturesAreActive" middleware.

* formatting

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
ash-jc-allen and taylorotwell authored Aug 30, 2023
1 parent 71b0235 commit 6cb8c00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Middleware/EnsureFeaturesAreActive.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function handle(Request $request, Closure $next, string ...$features): mi
return $next($request);
}

/**
* Specify the features for the middleware.
*/
public static function all(string ...$features): string
{
return static::class.':'.implode(',', $features);
}

/**
* Specify a callback that should be used to generate responses for failed feature checks.
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/FeatureMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ public function test_it_passes_if_all_features_are_enabled(): void
);
}

public function test_middleware_string_can_be_returned(): void
{
$this->assertEquals(
'Laravel\Pennant\Middleware\EnsureFeaturesAreActive:test,another',
EnsureFeaturesAreActive::all('test', 'another'),
);
}

protected function createRequest(string $uri, string $method): Request
{
$request = SymfonyRequest::create(
Expand Down

0 comments on commit 6cb8c00

Please sign in to comment.