12
12
namespace Symfony \Component \String \Tests ;
13
13
14
14
use Symfony \Component \String \AbstractString ;
15
- use function Symfony \Component \String \b ;
16
15
use Symfony \Component \String \ByteString ;
16
+ use Symfony \Component \String \Exception \InvalidArgumentException ;
17
17
18
18
class ByteStringTest extends AbstractAsciiTestCase
19
19
{
@@ -22,43 +22,46 @@ protected static function createFromString(string $string): AbstractString
22
22
return new ByteString ($ string );
23
23
}
24
24
25
- public function testFromRandom (): void
25
+ public function testFromRandom ()
26
26
{
27
27
$ random = ByteString::fromRandom (32 );
28
28
29
29
self ::assertSame (32 , $ random ->length ());
30
30
foreach ($ random ->chunk () as $ char ) {
31
- self ::assertNotNull (b ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ' )->indexOf ($ char ));
31
+ self ::assertNotNull (( new ByteString ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ' ) )->indexOf ($ char ));
32
32
}
33
33
}
34
34
35
- public function testFromRandomWithSpecificChars (): void
35
+ public function testFromRandomWithSpecificChars ()
36
36
{
37
37
$ random = ByteString::fromRandom (32 , 'abc ' );
38
38
39
39
self ::assertSame (32 , $ random ->length ());
40
40
foreach ($ random ->chunk () as $ char ) {
41
- self ::assertNotNull (b ( 'abc ' )->indexOf ($ char ));
41
+ self ::assertNotNull (( new ByteString ( 'abc ' ) )->indexOf ($ char ));
42
42
}
43
43
}
44
44
45
- public function testFromRandomEarlyReturnForZeroLength (): void
45
+ public function testFromRandoWithZeroLength ()
46
46
{
47
+ $ this ->expectException (InvalidArgumentException::class);
48
+ $ this ->expectExceptionMessage ('A strictly positive length is expected, "0" given. ' );
49
+
47
50
self ::assertSame ('' , ByteString::fromRandom (0 ));
48
51
}
49
52
50
- public function testFromRandomThrowsForNegativeLength (): void
53
+ public function testFromRandomThrowsForNegativeLength ()
51
54
{
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. ' );
54
57
55
58
ByteString::fromRandom (-1 );
56
59
}
57
60
58
- public function testFromRandomAlphabetMin (): void
61
+ public function testFromRandomAlphabetMin ()
59
62
{
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. ' );
62
65
63
66
ByteString::fromRandom (32 , 'a ' );
64
67
}
0 commit comments