Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backfill tests for the Flip helper (feels like a helper anyways)
- Loading branch information
1 parent
cee619b
commit d89d53c
Showing
5 changed files
with
174 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Vehikl\Flip\Tests; | ||
|
||
use Vehikl\Flip\Featurable; | ||
|
||
class SomeClass | ||
{ | ||
use Featurable; | ||
|
||
protected $features = [ | ||
SomeFeature::class, | ||
SomeOtherFeature::class, | ||
]; | ||
|
||
public function go(): string | ||
{ | ||
return 'going!'; | ||
} | ||
|
||
public function someToggledMethod(): string | ||
{ | ||
return $this->flip()->someOtherToggle(); | ||
} | ||
} |
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,80 @@ | ||
<?php | ||
|
||
namespace Vehikl\Flip\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Framework\TestResult; | ||
use Vehikl\Flip\Feature; | ||
|
||
class SomeFeature extends Feature | ||
{ | ||
private $enabled = false; | ||
private $invokedMethod; | ||
|
||
public function toggles(): array | ||
{ | ||
return ['someToggle' => ['on' => 'whenSomeToggleIsOn', 'off' => 'whenSomeToggleIsOff'], 'anotherToggle' => ['on' => 'whenAnotherToggleIsOn', 'off' => 'whenAnotherToggleIsOff',], 'staticToggle' => ['on' => 'whenStaticToggleIsOn', 'off' => 'whenStaticToggleIsOff',], 'bustedToggle' => ['on' => 'whenBustedToggleIsOn', 'off' => 'whenBustedToggleIsOff',]]; | ||
} | ||
|
||
public function enabled(): bool | ||
{ | ||
return $this->enabled; | ||
} | ||
|
||
public function turnOn(): self | ||
{ | ||
$this->enabled = true; | ||
|
||
return $this; | ||
} | ||
|
||
public function turnOff(): self | ||
{ | ||
$this->enabled = false; | ||
|
||
return $this; | ||
} | ||
|
||
public function whenSomeToggleIsOn(): string | ||
{ | ||
return $this->invokedMethod = 'whenOn'; | ||
} | ||
|
||
public function whenSomeToggleIsOff(): string | ||
{ | ||
return $this->invokedMethod = 'whenOff'; | ||
} | ||
|
||
public function invokedMethod(): string | ||
{ | ||
return $this->invokedMethod; | ||
} | ||
|
||
public function whenAnotherToggleIsOn(): string | ||
{ | ||
return $this->toString(); | ||
} | ||
|
||
public function whenAnotherToggleIsOff(): TestResult | ||
{ | ||
return $this->createResult(); | ||
} | ||
|
||
public function whenStaticToggleIsOn(): void | ||
{ | ||
} | ||
|
||
public function whenStaticToggleIsOff(): TestCase | ||
{ | ||
return $this->caller; | ||
} | ||
|
||
public function whenBustedToggleIsOn(): void | ||
{ | ||
} | ||
|
||
public function whenBustedToggleIsOff(): void | ||
{ | ||
$this->nope(); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
namespace Vehikl\Flip\Tests; | ||
|
||
use Vehikl\Flip\Feature; | ||
|
||
class SomeOtherFeature extends Feature | ||
{ | ||
public function toggles(): array | ||
{ | ||
return ['someOtherToggle' => ['on' => 'whenSomeOtherToggleIsOn', 'off' => 'whenSomeOtherToggleIsOff']]; | ||
} | ||
|
||
public function enabled(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function whenSomeOtherToggleIsOn() | ||
{ | ||
return 'whenSomeOtherToggleIsOn'; | ||
} | ||
|
||
public function whenSomeOtherToggleIsOff() | ||
{ | ||
return 'whenSomeOtherToggleIsOff'; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Vehikl\Flip\Tests\Unit; | ||
|
||
use Vehikl\Flip\Flip; | ||
use PHPUnit\Framework\TestCase; | ||
use Vehikl\Flip\Tests\SomeClass; | ||
use Vehikl\Flip\Tests\SomeFeature; | ||
use Vehikl\Flip\Tests\SomeOtherFeature; | ||
|
||
class FlipTest extends TestCase | ||
{ | ||
public function test_it_calls_feature_methods() | ||
{ | ||
$flip = new Flip(new SomeClass, [SomeFeature::class]); | ||
|
||
$this->assertEquals('whenOff', $flip->someToggle()); | ||
} | ||
|
||
public function test_it_calls_methods_on_the_class_if_there_are_no_applicable_features() | ||
{ | ||
$flip = new Flip(new SomeClass, [SomeFeature::class]); | ||
|
||
$this->assertEquals('going!', $flip->go()); | ||
} | ||
|
||
public function test_it_can_select_the_correct_toggle_to_run_from_multiple_features() | ||
{ | ||
$flip = new Flip(new SomeClass, [SomeFeature::class, SomeOtherFeature::class]); | ||
|
||
$this->assertEquals('whenSomeOtherToggleIsOn', $flip->someOtherToggle()); | ||
} | ||
|
||
public function test_the_flip_trait_makes_calling_features_easier() | ||
{ | ||
$someClass = new SomeClass; | ||
|
||
$this->assertEquals('whenSomeOtherToggleIsOn', $someClass->someToggledMethod()); | ||
} | ||
} |