diff --git a/app/Console/Commands/OperationActivate.php b/app/Console/Commands/OperationActivate.php new file mode 100644 index 00000000..9d183a5e --- /dev/null +++ b/app/Console/Commands/OperationActivate.php @@ -0,0 +1,22 @@ +activate('operation'); + + $this->line('Activated'); + + return self::SUCCESS; + } +} diff --git a/app/Console/Commands/OperationDeactivate.php b/app/Console/Commands/OperationDeactivate.php new file mode 100644 index 00000000..3beef04e --- /dev/null +++ b/app/Console/Commands/OperationDeactivate.php @@ -0,0 +1,22 @@ +deactivate('operation'); + + $this->line('Deactivated'); + + return self::SUCCESS; + } +} diff --git a/app/Console/Commands/OperationStatus.php b/app/Console/Commands/OperationStatus.php new file mode 100644 index 00000000..7e3c1e59 --- /dev/null +++ b/app/Console/Commands/OperationStatus.php @@ -0,0 +1,22 @@ +when('operation', fn() => 'Active', fn() => 'Inactive'); + + $this->line($status); + + return self::SUCCESS; + } +} diff --git a/app/Features/Operation.php b/app/Features/Operation.php new file mode 100644 index 00000000..abe6b85b --- /dev/null +++ b/app/Features/Operation.php @@ -0,0 +1,18 @@ +name = 'operation'; + } + + public function resolve(): bool + { + return true; + } +} diff --git a/app/Providers/FeatureFlagsServiceProvider.php b/app/Providers/FeatureFlagsServiceProvider.php index af7c0acb..4fbae52a 100644 --- a/app/Providers/FeatureFlagsServiceProvider.php +++ b/app/Providers/FeatureFlagsServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Features\Operation; use Illuminate\Support\ServiceProvider; use Laravel\Pennant\Feature; @@ -9,5 +10,6 @@ class FeatureFlagsServiceProvider extends ServiceProvider { public function boot(): void { + Feature::define(Operation::class); } } diff --git a/resources/views/inc/app/navigation-bar.blade.php b/resources/views/inc/app/navigation-bar.blade.php index c0b59bad..ee137fcb 100644 --- a/resources/views/inc/app/navigation-bar.blade.php +++ b/resources/views/inc/app/navigation-bar.blade.php @@ -5,15 +5,17 @@
Rs.{{number_format($product->price)}}
@endifWe're sorry. We cannot find any matches for your search term.
- +{{ $product->product_code }}
-- - @if ($product->stock > 0) -
+ + @if ($product->stock > 0) +
diff --git a/tests/Feature/Http/Controllers/User/CatalogPageTest.php b/tests/Feature/Http/Controllers/User/CatalogPageTest.php index 2f13280f..7f8fad8c 100644 --- a/tests/Feature/Http/Controllers/User/CatalogPageTest.php +++ b/tests/Feature/Http/Controllers/User/CatalogPageTest.php @@ -2,7 +2,10 @@ namespace Tests\Feature\Http\Controllers\User; +use App\Features\Operation; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Artisan; +use Laravel\Pennant\Feature; use PHPUnit\Framework\Attributes\Test; use Tests\TestCase; @@ -17,4 +20,26 @@ public function seeBasicItem() ->assertSeeText('Categories') ->assertSeeText('Price'); } + + #[Test] + public function seeCartItemWhenFeatureOn() + { + Artisan::call('db:seed'); + + Feature::activate(Operation::class); + + $this->get('/catalog') + ->assertSeeText('Add to cart'); + } + + #[Test] + public function dontSeeCartItemWhenFeatureOff() + { + Artisan::call('db:seed'); + + Feature::deactivate(Operation::class); + + $this->get('/catalog') + ->assertDontSeeText('Add to cart'); + } } diff --git a/tests/Feature/Http/Controllers/User/ShopTest.php b/tests/Feature/Http/Controllers/User/ShopTest.php index 9bf9e773..082d2ad7 100644 --- a/tests/Feature/Http/Controllers/User/ShopTest.php +++ b/tests/Feature/Http/Controllers/User/ShopTest.php @@ -2,7 +2,9 @@ namespace Tests\Feature\Http\Controllers\User; +use App\Features\Operation; use Illuminate\Foundation\Testing\RefreshDatabase; +use Laravel\Pennant\Feature; use PHPUnit\Framework\Attributes\Test; use Tests\TestCase;