Skip to content

Commit

Permalink
Use class
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesChou committed Aug 4, 2023
1 parent b225fbb commit 9063db2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
18 changes: 18 additions & 0 deletions app/Features/Operation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Features;

class Operation
{
public readonly string $name;

public function __construct()
{
$this->name = 'operation';
}

public function resolve(): bool
{
return true;
}
}
3 changes: 2 additions & 1 deletion app/Providers/FeatureFlagsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace App\Providers;

use App\Features\Operation;
use Illuminate\Support\ServiceProvider;
use Laravel\Pennant\Feature;

class FeatureFlagsServiceProvider extends ServiceProvider
{
public function boot(): void
{
Feature::define('operation', fn() => true);
Feature::define(Operation::class);
}
}
5 changes: 3 additions & 2 deletions tests/Feature/Http/Controllers/User/CatalogPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\Http\Controllers\User;

use App\Features\Operation;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Laravel\Pennant\Feature;
Expand All @@ -25,7 +26,7 @@ public function seeCartItemWhenFeatureOn()
{
Artisan::call('db:seed');

Feature::activate('operation');
Feature::activate(Operation::class);

$this->get('/catalog')
->assertSeeText('Add to cart');
Expand All @@ -36,7 +37,7 @@ public function dontSeeCartItemWhenFeatureOff()
{
Artisan::call('db:seed');

Feature::deactivate('operation');
Feature::deactivate(Operation::class);

$this->get('/catalog')
->assertDontSeeText('Add to cart');
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/Http/Controllers/User/ShopTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Tests\Feature\Http\Controllers\User;

use App\Features\Operation;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Pennant\Feature;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -22,7 +23,7 @@ public function seeBasicTitle()
#[Test]
public function seeLoginItemWhenOperationFeatureOn()
{
Feature::activate('operation');
Feature::activate(Operation::class);

$this->get('/catalog')
->assertSeeText('Track my order')
Expand All @@ -33,7 +34,7 @@ public function seeLoginItemWhenOperationFeatureOn()
#[Test]
public function dontSeeLoginItemWhenOperationFeatureOff()
{
Feature::deactivate('operation');
Feature::deactivate(Operation::class);

$this->get('/catalog')
->assertDontSeeText('Track my order')
Expand Down

0 comments on commit 9063db2

Please sign in to comment.