Skip to content

Commit

Permalink
[toggle-core#16] Create FeatureWasCreated event
Browse files Browse the repository at this point in the history
  • Loading branch information
pcs289 committed Oct 3, 2021
1 parent e2efb7c commit bc2b773
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/Write/Event/FeatureWasCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Pheature\Core\Toggle\Write\Event;

final class FeatureWasCreated
{

private string $eventType;

private string $featureId;

public function __construct(string $featureId)
{
$this->featureId = $featureId;
$this->eventType = "FEATURE_WAS_CREATED";
}

public function eventType(): string
{
return $this->eventType;
}

public function featureId(): string
{
return $this->featureId;
}

public static function fromString(string $payload): self
{
return new self($payload);
}
}
2 changes: 2 additions & 0 deletions src/Write/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Pheature\Core\Toggle\Write;

use Pheature\Core\Toggle\Write\Event\FeatureWasCreated;
use JsonSerializable;

use function array_map;
Expand Down Expand Up @@ -32,6 +33,7 @@ public function __construct(FeatureId $featureId, bool $enabled, array $strategi
foreach ($strategies as $strategy) {
$this->strategies[$strategy->id()->value()] = $strategy;
}
$this->events[] = new FeatureWasCreated($featureId->value());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions test/Write/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testItShouldBeEnabled(): void
$feature->enable();
$this->assertTrue($feature->isEnabled());
$events = $feature->release();
$this->assertCount(0, $events);
$this->assertCount(1, $events); // Released FeatureWasCreated event
}

public function testItShouldBeDisabled(): void
Expand All @@ -58,15 +58,15 @@ public function testItShouldBeDisabled(): void
$feature->disable();
$this->assertFalse($feature->isEnabled());
$events = $feature->release();
$this->assertCount(0, $events);
$this->assertCount(1, $events); // Released FeatureWasCreated event
}

public function testItShouldHaveAddedStrategies(): void
{
$feature = $this->getFeatureWithAnStrategy();
$this->assertCount(1, $feature->strategies());
$events = $feature->release();
$this->assertCount(0, $events);
$this->assertCount(1, $events); // Released FeatureWasCreated event
}

public function testItShouldRemoveAddedStrategies(): void
Expand All @@ -77,7 +77,7 @@ public function testItShouldRemoveAddedStrategies(): void
$feature->removeStrategy(StrategyId::fromString(self::STRATEGY_ID));
$this->assertCount(0, $feature->strategies());
$events = $feature->release();
$this->assertCount(0, $events);
$this->assertCount(1, $events); // Released FeatureWasCreated event
}

private function createFeature(): Feature
Expand Down

0 comments on commit bc2b773

Please sign in to comment.