55use PhpTypedValues \Abstract \AbstractType ;
66use PhpTypedValues \Exception \TypeException ;
77
8+ abstract readonly class AbstractTypeTest extends AbstractType
9+ {
10+ public static function convert (mixed $ value ): string
11+ {
12+ return self ::convertMixedToString ($ value );
13+ }
14+ }
15+
816it ('convertMixedToString casts scalars and null to string ' , function (): void {
9- expect (AbstractType:: convertMixedToString (123 ))->toBe ('123 ' )
10- ->and (AbstractType:: convertMixedToString (1.5 ))->toBe ('1.5 ' )
11- ->and (AbstractType:: convertMixedToString ('foo ' ))->toBe ('foo ' )
12- ->and (AbstractType:: convertMixedToString (true ))->toBe ('1 ' )
13- ->and (AbstractType:: convertMixedToString (false ))->toBe ('' )
14- ->and (AbstractType:: convertMixedToString (null ))->toBe ('' );
17+ expect (AbstractTypeTest:: convert (123 ))->toBe ('123 ' )
18+ ->and (AbstractTypeTest:: convert (1.5 ))->toBe ('1.5 ' )
19+ ->and (AbstractTypeTest:: convert ('foo ' ))->toBe ('foo ' )
20+ ->and (AbstractTypeTest:: convert (true ))->toBe ('1 ' )
21+ ->and (AbstractTypeTest:: convert (false ))->toBe ('' )
22+ ->and (AbstractTypeTest:: convert (null ))->toBe ('' );
1523});
1624
1725it ('convertMixedToString accepts Stringable objects ' , function (): void {
@@ -22,22 +30,22 @@ public function __toString(): string
2230 }
2331 };
2432
25- expect (AbstractType:: convertMixedToString ($ obj ))->toBe ('3.5 ' );
33+ expect (AbstractTypeTest:: convert ($ obj ))->toBe ('3.5 ' );
2634});
2735
2836it ('convertMixedToString throws TypeException for non-stringable objects, arrays and resources ' , function (): void {
2937 // array
30- expect (fn () => AbstractType:: convertMixedToString (['x ' ]))
38+ expect (fn () => AbstractTypeTest:: convert (['x ' ]))
3139 ->toThrow (TypeException::class, 'Value cannot be cast to string ' );
3240
3341 // stdClass (non-stringable)
34- expect (fn () => AbstractType:: convertMixedToString (new stdClass ()))
42+ expect (fn () => AbstractTypeTest:: convert (new stdClass ()))
3543 ->toThrow (TypeException::class, 'Value cannot be cast to string ' );
3644
3745 // resource
3846 $ res = fopen ('php://memory ' , 'r ' );
3947 try {
40- expect (fn () => AbstractType:: convertMixedToString ($ res ))
48+ expect (fn () => AbstractTypeTest:: convert ($ res ))
4149 ->toThrow (TypeException::class, 'Value cannot be cast to string ' );
4250 } finally {
4351 \is_resource ($ res ) && fclose ($ res );
0 commit comments