-
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.
* implement query activator * update readme
- Loading branch information
Showing
9 changed files
with
125 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chaos\Monkey\Symfony\Activator; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class QueryParamActivator | ||
{ | ||
public function __construct(private readonly bool $enabled = false, private readonly string $paramName = 'chaos') | ||
{ | ||
} | ||
|
||
public function inChaos(Request $request): bool | ||
{ | ||
if (!$this->enabled) { | ||
return true; | ||
} | ||
|
||
return $request->query->has($this->paramName); | ||
} | ||
} |
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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chaos\Monkey\Symfony\Tests\Activator; | ||
|
||
use Chaos\Monkey\Symfony\Activator\QueryParamActivator; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class QueryParamActivatorTest extends TestCase | ||
{ | ||
public function testItIsInChaosIfDisabled(): void | ||
{ | ||
$activator = new QueryParamActivator(); | ||
|
||
self::assertTrue($activator->inChaos(new Request())); | ||
} | ||
|
||
public function testItIsNoInChaosIfEnabledAndParamMissing(): void | ||
{ | ||
$activator = new QueryParamActivator(true); | ||
|
||
self::assertFalse($activator->inChaos(new Request())); | ||
} | ||
|
||
public function testItIsInChaosIfEnabledAndParamExists(): void | ||
{ | ||
$activator = new QueryParamActivator(true, 'bye'); | ||
|
||
self::assertTrue($activator->inChaos(new Request(['bye' => true]))); | ||
} | ||
} |
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