Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesChou committed Aug 4, 2023
1 parent 5711b41 commit b225fbb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Console/Commands/OperationActivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function handle(FeatureManager $feature): int
{
$feature->activate('operation');

$this->line('Activated');

return self::SUCCESS;
}
}
2 changes: 2 additions & 0 deletions app/Console/Commands/OperationDeactivate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function handle(FeatureManager $feature): int
{
$feature->deactivate('operation');

$this->line('Deactivated');

return self::SUCCESS;
}
}
1 change: 1 addition & 0 deletions app/Providers/FeatureFlagsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class FeatureFlagsServiceProvider extends ServiceProvider
{
public function boot(): void
{
Feature::define('operation', fn() => true);
}
}
24 changes: 24 additions & 0 deletions tests/Feature/Http/Controllers/User/CatalogPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Tests\Feature\Http\Controllers\User;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Laravel\Pennant\Feature;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

Expand All @@ -17,4 +19,26 @@ public function seeBasicItem()
->assertSeeText('Categories')
->assertSeeText('Price');
}

#[Test]
public function seeCartItemWhenFeatureOn()
{
Artisan::call('db:seed');

Feature::activate('operation');

$this->get('/catalog')
->assertSeeText('Add to cart');
}

#[Test]
public function dontSeeCartItemWhenFeatureOff()
{
Artisan::call('db:seed');

Feature::deactivate('operation');

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

use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Pennant\Feature;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

Expand All @@ -17,4 +18,26 @@ public function seeBasicTitle()
->assertSeeText('Categories')
->assertSeeText('Just For You');
}

#[Test]
public function seeLoginItemWhenOperationFeatureOn()
{
Feature::activate('operation');

$this->get('/catalog')
->assertSeeText('Track my order')
->assertSeeText('Login')
->assertSeeText('Sign up');
}

#[Test]
public function dontSeeLoginItemWhenOperationFeatureOff()
{
Feature::deactivate('operation');

$this->get('/catalog')
->assertDontSeeText('Track my order')
->assertDontSeeText('Login')
->assertDontSeeText('Sign up');
}
}

0 comments on commit b225fbb

Please sign in to comment.