-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d71a8a2
commit 73869ed
Showing
6 changed files
with
208 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace PodPoint\ConfigCat\Tests\Feature; | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use PodPoint\ConfigCat\Facades\ConfigCat; | ||
use PodPoint\ConfigCat\Tests\TestCase; | ||
|
||
class BladeDirectivesTest extends TestCase | ||
{ | ||
public function test_it_will_render_something_only_when_the_corresponding_feature_flag_is_enabled() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => true, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('I am hidden'); | ||
} | ||
|
||
public function test_it_will_consider_an_unknown_feature_flag_to_be_disabled() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => true, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertSee('You can see me'); | ||
} | ||
|
||
public function test_it_will_consider_a_feature_flag_as_a_number_setting_to_be_disabled() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => 123, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('I should be visible'); | ||
$this->get('/foo')->assertSee('I should not be visible'); | ||
} | ||
|
||
public function test_it_will_consider_a_feature_flag_as_a_text_setting_to_be_disabled() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => 'foobar', | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('I should be visible'); | ||
$this->get('/foo')->assertSee('I should not be visible'); | ||
} | ||
|
||
public function test_it_supports_the_unlessconfigcat_directive() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => true, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertSee('I am not hidden'); | ||
} | ||
|
||
public function test_it_supports_the_else_directive() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => false, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('I should be visible'); | ||
$this->get('/foo')->assertSee('I should not be visible'); | ||
} | ||
|
||
public function test_it_supports_the_elseconfigcat_directive() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => true, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('You cannot see me'); | ||
$this->get('/foo')->assertSee('You can see me'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,15 @@ | ||
<?php | ||
|
||
namespace PodPoint\ConfigCat\Tests\Feature; | ||
namespace PodPoint\ConfigCat\Tests\Feature\Facades; | ||
|
||
use ConfigCat\ClientInterface; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Facades\Route; | ||
use Mockery\MockInterface; | ||
use PodPoint\ConfigCat\Facades\ConfigCat; | ||
use PodPoint\ConfigCat\Tests\TestCase; | ||
|
||
class ConfigCatTest extends TestCase | ||
{ | ||
public function test_global_helper_can_be_used_to_check_if_a_feature_flag_is_enabled_or_disabled() | ||
{ | ||
ConfigCat::fake([ | ||
'some_enabled_feature' => true, | ||
'some_disabled_feature' => false, | ||
]); | ||
|
||
$this->assertTrue(configcat('some_enabled_feature')); | ||
$this->assertFalse(configcat('some_disabled_feature')); | ||
} | ||
|
||
public function test_global_helper_returns_false_when_a_feature_flag_does_not_exist() | ||
{ | ||
ConfigCat::fake(['some_feature' => true]); | ||
|
||
$this->assertFalse(configcat('some_unknown_feature')); | ||
} | ||
|
||
public function test_global_helper_can_retrieve_a_text_setting() | ||
{ | ||
ConfigCat::fake(['some_feature_as_a_string' => 'foo']); | ||
|
||
$this->assertEquals('foo', configcat('some_feature_as_a_string')); | ||
} | ||
|
||
public function test_global_helper_can_retrieve_a_number_setting() | ||
{ | ||
ConfigCat::fake(['some_feature_as_a_string' => 123]); | ||
|
||
$this->assertEquals(123, configcat('some_feature_as_a_string')); | ||
} | ||
|
||
public function test_global_helper_relies_on_the_facade() | ||
{ | ||
ConfigCat::shouldReceive('get')->once()->with('some_feature'); | ||
|
||
configcat('some_feature'); | ||
} | ||
|
||
public function test_global_helper_can_be_used_with_a_given_user() | ||
{ | ||
$user = new \Illuminate\Foundation\Auth\User(); | ||
$user->id = 123; | ||
$user->email = '[email protected]'; | ||
|
||
ConfigCat::shouldReceive('get')->once()->with('some_feature', $user); | ||
|
||
configcat('some_feature', $user); | ||
} | ||
|
||
public function test_the_facade_can_override_feature_flags() | ||
{ | ||
config(['configcat.overrides.enabled' => true]); | ||
|
@@ -80,35 +29,6 @@ public function test_the_facade_can_override_feature_flags() | |
); | ||
} | ||
|
||
public function test_the_blade_directive_will_render_something_only_when_the_corresponding_feature_flag_is_enabled() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => true, | ||
'disabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertSee('I should be visible'); | ||
$this->get('/foo')->assertDontSee('I am hidden'); | ||
} | ||
|
||
public function test_the_blade_directive_supports_the_else_directive() | ||
{ | ||
ConfigCat::fake([ | ||
'enabled_feature' => false, | ||
]); | ||
|
||
Route::get('/foo', function () { | ||
return view('feature'); | ||
}); | ||
|
||
$this->get('/foo')->assertDontSee('I should be visible'); | ||
$this->get('/foo')->assertSee('I should not be visible'); | ||
} | ||
|
||
public function test_config_cat_client_is_called_when_resolving_feature_flags() | ||
{ | ||
$this->mock(ClientInterface::class, function (MockInterface $mock) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace PodPoint\ConfigCat\Tests\Feature; | ||
|
||
use PodPoint\ConfigCat\Facades\ConfigCat; | ||
use PodPoint\ConfigCat\Tests\TestCase; | ||
|
||
class HelperTest extends TestCase | ||
{ | ||
public function test_global_helper_can_be_used_to_check_if_a_feature_flag_is_enabled_or_disabled() | ||
{ | ||
ConfigCat::fake([ | ||
'some_enabled_feature' => true, | ||
'some_disabled_feature' => false, | ||
]); | ||
|
||
$this->assertTrue(configcat('some_enabled_feature')); | ||
$this->assertFalse(configcat('some_disabled_feature')); | ||
} | ||
|
||
public function test_global_helper_returns_false_when_a_feature_flag_does_not_exist() | ||
{ | ||
ConfigCat::fake(['some_feature' => true]); | ||
|
||
$this->assertFalse(configcat('some_unknown_feature')); | ||
} | ||
|
||
public function test_global_helper_can_retrieve_a_text_setting() | ||
{ | ||
ConfigCat::fake(['some_feature_as_a_string' => 'foo']); | ||
|
||
$this->assertEquals('foo', configcat('some_feature_as_a_string')); | ||
} | ||
|
||
public function test_global_helper_can_retrieve_a_number_setting() | ||
{ | ||
ConfigCat::fake(['some_feature_as_a_string' => 123]); | ||
|
||
$this->assertEquals(123, configcat('some_feature_as_a_string')); | ||
} | ||
|
||
public function test_global_helper_relies_on_the_facade() | ||
{ | ||
ConfigCat::shouldReceive('get')->once()->with('some_feature'); | ||
|
||
configcat('some_feature'); | ||
} | ||
|
||
public function test_global_helper_can_be_used_with_a_given_user() | ||
{ | ||
$user = new \Illuminate\Foundation\Auth\User(); | ||
$user->id = 123; | ||
$user->email = '[email protected]'; | ||
|
||
ConfigCat::shouldReceive('get')->once()->with('some_feature', $user); | ||
|
||
configcat('some_feature', $user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
<html> | ||
<body> | ||
@configcat('disabled_feature') | ||
I am hidden | ||
@endconfigcat | ||
|
||
@unlessconfigcat('disabled_feature') | ||
I am not hidden | ||
@endconfigcat | ||
|
||
@configcat('enabled_feature') | ||
I should be visible | ||
I should be visible | ||
@else | ||
I should not be visible | ||
I should not be visible | ||
@endconfigcat | ||
|
||
@configcat('disabled_feature') | ||
I am hidden | ||
@configcat('unknown_feature') | ||
You cannot see me | ||
@elseconfigcat('enabled_feature') | ||
You can see me | ||
@endconfigcat | ||
</body> | ||
</html> |