This repository was archived by the owner on Nov 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +57
-2
lines changed
tests/unit/domain/command Expand file tree Collapse file tree 5 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types=1 );
2+ namespace example \caledonia \domain ;
3+
4+ /**
5+ * @no-named-arguments
6+ */
7+ abstract readonly class Command
8+ {
9+ /**
10+ * @return non-empty-string
11+ */
12+ abstract public function asString (): string ;
13+ }
Original file line number Diff line number Diff line change 11<?php declare (strict_types=1 );
22namespace example \caledonia \domain ;
33
4+ use function sprintf ;
5+
46/**
57 * @no-named-arguments
68 */
7- final readonly class PurchaseGoodCommand
9+ final readonly class PurchaseGoodCommand extends Command
810{
911 private Good $ good ;
1012
@@ -34,4 +36,16 @@ public function amount(): int
3436 {
3537 return $ this ->amount ;
3638 }
39+
40+ /**
41+ * @return non-empty-string
42+ */
43+ public function asString (): string
44+ {
45+ return sprintf (
46+ 'Purchase %d %s ' ,
47+ $ this ->amount ,
48+ $ this ->good ->value ,
49+ );
50+ }
3751}
Original file line number Diff line number Diff line change 11<?php declare (strict_types=1 );
22namespace example \caledonia \domain ;
33
4+ use function sprintf ;
5+
46/**
57 * @no-named-arguments
68 */
7- final readonly class SellGoodCommand
9+ final readonly class SellGoodCommand extends Command
810{
911 private Good $ good ;
1012
@@ -34,4 +36,16 @@ public function amount(): int
3436 {
3537 return $ this ->amount ;
3638 }
39+
40+ /**
41+ * @return non-empty-string
42+ */
43+ public function asString (): string
44+ {
45+ return sprintf (
46+ 'Sell %d %s ' ,
47+ $ this ->amount ,
48+ $ this ->good ->value ,
49+ );
50+ }
3751}
Original file line number Diff line number Diff line change @@ -27,4 +27,11 @@ public function testHasAmount(): void
2727
2828 $ this ->assertSame (1 , $ command ->amount ());
2929 }
30+
31+ public function testCanBeRepresentedAsString (): void
32+ {
33+ $ command = new PurchaseGoodCommand (Good::Bread, 1 );
34+
35+ $ this ->assertSame ('Purchase 1 bread ' , $ command ->asString ());
36+ }
3037}
Original file line number Diff line number Diff line change @@ -27,4 +27,11 @@ public function testHasAmount(): void
2727
2828 $ this ->assertSame (1 , $ command ->amount ());
2929 }
30+
31+ public function testCanBeRepresentedAsString (): void
32+ {
33+ $ command = new SellGoodCommand (Good::Bread, 1 );
34+
35+ $ this ->assertSame ('Sell 1 bread ' , $ command ->asString ());
36+ }
3037}
You can’t perform that action at this time.
0 commit comments