Skip to content

Commit 0333d9d

Browse files
Fix tests
1 parent 3bee3d2 commit 0333d9d

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

ByteString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public function __construct(string $string = '')
4545
public static function fromRandom(int $length = 16, string $alphabet = null): self
4646
{
4747
if ($length <= 0) {
48-
throw new InvalidArgumentException(sprintf('Expected positive length value, got "%d".', $length));
48+
throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length));
4949
}
5050

5151
$alphabet = $alphabet ?? self::ALPHABET_ALPHANUMERIC;
5252
$alphabetSize = \strlen($alphabet);
5353
$bits = (int) ceil(log($alphabetSize, 2.0));
5454
if ($bits <= 0 || $bits > 56) {
55-
throw new InvalidArgumentException('Expected $alphabet\'s length to be in [2^1, 2^56].');
55+
throw new InvalidArgumentException('The length of the alphabet must in the [2^1, 2^56] range.');
5656
}
5757

5858
$ret = '';

Tests/ByteStringTest.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\String\Tests;
1313

1414
use Symfony\Component\String\AbstractString;
15-
use function Symfony\Component\String\b;
1615
use Symfony\Component\String\ByteString;
16+
use Symfony\Component\String\Exception\InvalidArgumentException;
1717

1818
class 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

Comments
 (0)