-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
11 changed files
with
118 additions
and
107 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pheature\Crud\Toggle\Command; | ||
|
||
use Pheature\Core\Toggle\Write\FeatureId; | ||
use Pheature\Core\Toggle\Write\StrategyId; | ||
|
||
final class RemoveStrategy | ||
{ | ||
private FeatureId $featureId; | ||
private StrategyId $strategyId; | ||
|
||
private function __construct(string $featureId, string $strategyId) | ||
{ | ||
$this->featureId = FeatureId::fromString($featureId); | ||
$this->strategyId = StrategyId::fromString($strategyId); | ||
} | ||
|
||
public static function withFeatureAndStrategyId(string $featureId, string $strategyId): self | ||
{ | ||
return new self($featureId, $strategyId); | ||
} | ||
|
||
public function featureId(): FeatureId | ||
{ | ||
return $this->featureId; | ||
} | ||
|
||
public function strategyId(): StrategyId | ||
{ | ||
return $this->strategyId; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pheature\Crud\Toggle\Handler; | ||
|
||
use Pheature\Core\Toggle\Write\FeatureRepository; | ||
use Pheature\Crud\Toggle\Command\RemoveStrategy as RemoveStrategyCommand; | ||
|
||
final class RemoveStrategy | ||
{ | ||
private FeatureRepository $featureRepository; | ||
|
||
public function __construct(FeatureRepository $featureRepository) | ||
{ | ||
$this->featureRepository = $featureRepository; | ||
} | ||
|
||
public function handle(RemoveStrategyCommand $command): void | ||
{ | ||
$feature = $this->featureRepository->get($command->featureId()); | ||
|
||
$feature->removeStrategy($command->strategyId()); | ||
|
||
$this->featureRepository->save($feature); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Pheature\Test\Crud\Toggle\Handler; | ||
|
||
use Pheature\Core\Toggle\Write\Feature; | ||
use Pheature\Core\Toggle\Write\FeatureId; | ||
use Pheature\Core\Toggle\Write\FeatureRepository; | ||
use Pheature\Core\Toggle\Write\Strategy; | ||
use Pheature\Core\Toggle\Write\StrategyId; | ||
use Pheature\Core\Toggle\Write\StrategyType; | ||
use Pheature\Crud\Toggle\Command\RemoveStrategy as RemoveStrategyCommand; | ||
use Pheature\Crud\Toggle\Handler\RemoveStrategy; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class RemoveStrategyTest extends TestCase | ||
{ | ||
private const FEATURE_ID = '252f6942-20ac-4b69-960a-d4246b1895c8'; | ||
private const STRATEGY_ID = 'ec721d39-4665-48b8-8e6f-0de3af19cbaf'; | ||
private const STRATEGY_TYPE = 'some_strategy'; | ||
|
||
public function testItShouldAddStrategyToAFeature(): void | ||
{ | ||
$feature = Feature::withId(FeatureId::fromString(self::FEATURE_ID)); | ||
$feature->addStrategy(new Strategy( | ||
StrategyId::fromString(self::STRATEGY_ID), | ||
StrategyType::fromString(self::STRATEGY_TYPE) | ||
)); | ||
$command = RemoveStrategyCommand::withFeatureAndStrategyId(self::FEATURE_ID, self::STRATEGY_ID); | ||
$repository = $this->createMock(FeatureRepository::class); | ||
$repository->expects($this->once()) | ||
->method('get') | ||
->with($this->isInstanceOf(FeatureId::class)) | ||
->willReturn($feature); | ||
$repository->expects($this->once()) | ||
->method('save') | ||
->with($feature); | ||
|
||
$this->assertCount(1, $feature->strategies()); | ||
|
||
$handler = new RemoveStrategy($repository); | ||
$handler->handle($command); | ||
|
||
$this->assertCount(0, $feature->strategies()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.