New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[toggle-core#16] Create FeatureWasCreated event #24
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is better to work with generics at this level to easy serialization of the object, we create the value object in the getter as it is immutable |
||
{ | ||
$this->featureId = $featureId; | ||
$this->eventType = "FEATURE_WAS_CREATED"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could put the string in lowercase and extract it into a constant for future references. @kpicaza what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need event type the event class name is the type itself |
||
} | ||
|
||
public function eventType(): string | ||
{ | ||
kpicaza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return $this->eventType; | ||
} | ||
|
||
public function featureId(): string | ||
{ | ||
return $this->featureId; | ||
} | ||
|
||
public static function fromString(string $payload): self | ||
{ | ||
return new self($payload); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As @kpicaza commented, we could add an extra line here, checking the event type, for example:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We added a specific test for FeatureWasCreated event |
||||||||
} | ||||||||
|
||||||||
public function testItShouldBeDisabled(): void | ||||||||
|
@@ -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 | ||||||||
|
@@ -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 | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can define properties in the same order as they're assigned in the constructor: