1212namespace Symfony \Component \String \Tests ;
1313
1414use Symfony \Component \String \AbstractString ;
15- use function Symfony \Component \String \b ;
1615use Symfony \Component \String \ByteString ;
16+ use Symfony \Component \String \Exception \InvalidArgumentException ;
1717
1818class ByteStringTest extends AbstractAsciiTestCase
1919{
@@ -22,43 +22,46 @@ protected static function createFromString(string $string): AbstractString
2222 return new ByteString ($ string );
2323 }
2424
25- public function testFromRandom (): void
25+ public function testFromRandom ()
2626 {
2727 $ random = ByteString::fromRandom (32 );
2828
2929 self ::assertSame (32 , $ random ->length ());
3030 foreach ($ random ->chunk () as $ char ) {
31- self ::assertNotNull (b ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ' )->indexOf ($ char ));
31+ self ::assertNotNull (( new ByteString ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ' ) )->indexOf ($ char ));
3232 }
3333 }
3434
35- public function testFromRandomWithSpecificChars (): void
35+ public function testFromRandomWithSpecificChars ()
3636 {
3737 $ random = ByteString::fromRandom (32 , 'abc ' );
3838
3939 self ::assertSame (32 , $ random ->length ());
4040 foreach ($ random ->chunk () as $ char ) {
41- self ::assertNotNull (b ( 'abc ' )->indexOf ($ char ));
41+ self ::assertNotNull (( new ByteString ( 'abc ' ) )->indexOf ($ char ));
4242 }
4343 }
4444
45- public function testFromRandomEarlyReturnForZeroLength (): void
45+ public function testFromRandoWithZeroLength ()
4646 {
47+ $ this ->expectException (InvalidArgumentException::class);
48+ $ this ->expectExceptionMessage ('A strictly positive length is expected, "0" given. ' );
49+
4750 self ::assertSame ('' , ByteString::fromRandom (0 ));
4851 }
4952
50- public function testFromRandomThrowsForNegativeLength (): void
53+ public function testFromRandomThrowsForNegativeLength ()
5154 {
52- $ this ->expectException (\RuntimeException ::class);
53- $ this ->expectExceptionMessage ('Expected positive length value, got -1 ' );
55+ $ this ->expectException (InvalidArgumentException ::class);
56+ $ this ->expectExceptionMessage ('A strictly positive length is expected, "-1" given. ' );
5457
5558 ByteString::fromRandom (-1 );
5659 }
5760
58- public function testFromRandomAlphabetMin (): void
61+ public function testFromRandomAlphabetMin ()
5962 {
60- $ this ->expectException (\RuntimeException ::class);
61- $ this ->expectExceptionMessage ('Expected $alphabet \' s length to be in [2^1, 2^56] ' );
63+ $ this ->expectException (InvalidArgumentException ::class);
64+ $ this ->expectExceptionMessage ('The length of the alphabet must in the [2^1, 2^56] range. ' );
6265
6366 ByteString::fromRandom (32 , 'a ' );
6467 }
0 commit comments