File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed
Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -20,4 +20,9 @@ public static function fromBool(bool $value): static
2020 {
2121 return new static ($ value );
2222 }
23+
24+ public function __toString (): string
25+ {
26+ return $ this ->toString ();
27+ }
2328}
Original file line number Diff line number Diff line change 44
55namespace PhpTypedValues \Abstract \Bool ;
66
7+ use PhpTypedValues \Undefined \Alias \Undefined ;
8+
79/**
810 * @psalm-immutable
911 */
1012interface BoolTypeInterface
1113{
1214 public function value (): bool ;
1315
16+ public static function tryFromString (string $ value ): static |Undefined ;
17+
18+ public static function tryFromInt (int $ value ): static |Undefined ;
19+
1420 public static function fromString (string $ value ): static ;
1521
1622 public static function fromBool (bool $ value ): static ;
1723
1824 public function toString (): string ;
25+
26+ public function __toString (): string ;
1927}
Original file line number Diff line number Diff line change 77use PhpTypedValues \Abstract \Bool \BoolType ;
88use PhpTypedValues \Exception \BoolTypeException ;
99use PhpTypedValues \Exception \TypeException ;
10- use PhpTypedValues \Undefined \UndefinedStandard ;
10+ use PhpTypedValues \Undefined \Alias \ Undefined ;
1111
1212use function sprintf ;
1313
@@ -27,21 +27,21 @@ public function __construct(bool $value)
2727 $ this ->value = $ value ;
2828 }
2929
30- public static function tryFromString (string $ value ): static |UndefinedStandard
30+ public static function tryFromString (string $ value ): static |Undefined
3131 {
3232 try {
3333 return static ::fromString ($ value );
3434 } catch (TypeException ) {
35- return UndefinedStandard ::create ();
35+ return Undefined ::create ();
3636 }
3737 }
3838
39- public static function tryFromInt (int $ value ): static |UndefinedStandard
39+ public static function tryFromInt (int $ value ): static |Undefined
4040 {
4141 try {
4242 return static ::fromInt ($ value );
4343 } catch (TypeException ) {
44- return UndefinedStandard ::create ();
44+ return Undefined ::create ();
4545 }
4646 }
4747
Original file line number Diff line number Diff line change 6464 ->and ($ ok ->value ())->toBeTrue ();
6565
6666 // Undefined type instance indicates failure without throwing
67- expect ($ fail ::class)->toBe (PhpTypedValues \Undefined \UndefinedStandard ::class);
67+ expect ($ fail ::class)->toBe (PhpTypedValues \Undefined \Alias \Undefined ::class);
6868});
6969
7070it ('tryFromInt returns Undefined on invalid input and BoolStandard on valid ' , function (): void {
7676 ->and ($ one ->value ())->toBeTrue ()
7777 ->and ($ zero )->toBeInstanceOf (BoolStandard::class)
7878 ->and ($ zero ->value ())->toBeFalse ()
79- ->and ($ bad ::class)->toBe (PhpTypedValues \Undefined \UndefinedStandard ::class);
79+ ->and ($ bad ::class)->toBe (PhpTypedValues \Undefined \Alias \Undefined ::class);
8080});
8181
8282it ('parses string values with surrounding whitespace ' , function (): void {
8585 ->and (BoolStandard::fromString (' on ' )->value ())->toBeTrue ()
8686 ->and (BoolStandard::fromString (' off ' )->value ())->toBeFalse ();
8787});
88+
89+ it ('casts to string via __toString magic method ' , function (): void {
90+ $ t = new BoolStandard (true );
91+ $ f = BoolStandard::fromBool (false );
92+
93+ expect ((string ) $ t )->toBe ('true ' )
94+ ->and ((string ) $ f )->toBe ('false ' );
95+ });
You can’t perform that action at this time.
0 commit comments