Skip to content

Commit

Permalink
Use union types
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunk3l committed Feb 25, 2024
1 parent 5215e23 commit bb093e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Behavioral/Command/SwitchButtonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class SwitchButtonCommand implements CommandInterface
{
private const COMMAND_MESSAGE = "Tv has been switched on.";

public function __construct(private ReceiverInterface $control)
public function __construct(private ReceiverInterface|false $control)
{
if ($control === false) {
throw new \InvalidArgumentException("ReceiverInterface must be valid");
}
}

public function execute(): string
Expand Down
6 changes: 6 additions & 0 deletions test/Behavioral/Command/SwitchButtonCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ public function testShouldExecuteSwitchButtonCommand()

$this->assertEquals(self::COMMAND_MESSAGE, $result);
}

public function testShouldFailInCaseReceiverIsNotValid()
{
$this->expectException(\InvalidArgumentException::class);
$result = (new SwitchButtonCommand(control: false));
}
}

0 comments on commit bb093e2

Please sign in to comment.