Skip to content

Commit 9d1ccc0

Browse files
committed
Rename getBytesFromAlphabet to getBytesFromString
1 parent 397050c commit 9d1ccc0

File tree

8 files changed

+41
-41
lines changed

8 files changed

+41
-41
lines changed

ext/random/random.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function getInt(int $min, int $max): int {}
137137

138138
public function getBytes(int $length): string {}
139139

140-
public function getBytesFromAlphabet(string $alphabet, int $length): string {}
140+
public function getBytesFromString(string $alphabet, int $length): string {}
141141

142142
public function shuffleArray(array $array): array {}
143143

ext/random/random_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/random/randomizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ PHP_METHOD(Random_Randomizer, pickArrayKeys)
244244
/* }}} */
245245

246246
/* {{{ Get Random Bytes for Alphabet */
247-
PHP_METHOD(Random_Randomizer, getBytesFromAlphabet)
247+
PHP_METHOD(Random_Randomizer, getBytesFromString)
248248
{
249249
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
250250
zend_long length;

ext/random/tests/03_randomizer/engine_unsafe_biased.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ try {
5050
}
5151

5252
try {
53-
var_dump(randomizer()->getBytesFromAlphabet('123', 10));
53+
var_dump(randomizer()->getBytesFromString('123', 10));
5454
} catch (Random\BrokenRandomEngineError $e) {
5555
echo $e->getMessage(), PHP_EOL;
5656
}
5757

5858
try {
59-
var_dump(randomizer()->getBytesFromAlphabet(str_repeat('a', 500), 10));
59+
var_dump(randomizer()->getBytesFromString(str_repeat('a', 500), 10));
6060
} catch (Random\BrokenRandomEngineError $e) {
6161
echo $e->getMessage(), PHP_EOL;
6262
}

ext/random/tests/03_randomizer/engine_unsafe_empty_string.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ try {
5050
}
5151

5252
try {
53-
var_dump(randomizer()->getBytesFromAlphabet('123', 10));
53+
var_dump(randomizer()->getBytesFromString('123', 10));
5454
} catch (Random\BrokenRandomEngineError $e) {
5555
echo $e->getMessage(), PHP_EOL;
5656
}
5757

5858
try {
59-
var_dump(randomizer()->getBytesFromAlphabet(str_repeat('a', 500), 10));
59+
var_dump(randomizer()->getBytesFromString(str_repeat('a', 500), 10));
6060
} catch (Random\BrokenRandomEngineError $e) {
6161
echo $e->getMessage(), PHP_EOL;
6262
}

ext/random/tests/03_randomizer/methods/getBytesFromAlphabet_error.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

ext/random/tests/03_randomizer/methods/getBytesFromAlphabet.phpt renamed to ext/random/tests/03_randomizer/methods/getBytesFromString.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Random: Randomizer: getBytesFromAlphabet(): Basic functionality
2+
Random: Randomizer: getBytesFromString(): Basic functionality
33
--FILE--
44
<?php
55

@@ -25,11 +25,11 @@ foreach ($engines as $engine) {
2525
echo $engine::class, PHP_EOL;
2626

2727
$randomizer = new Randomizer($engine);
28-
var_dump($randomizer->getBytesFromAlphabet('a', 10));
29-
var_dump($randomizer->getBytesFromAlphabet(str_repeat('a', 256), 5));
28+
var_dump($randomizer->getBytesFromString('a', 10));
29+
var_dump($randomizer->getBytesFromString(str_repeat('a', 256), 5));
3030

3131
for ($i = 1; $i < 250; $i++) {
32-
$output = $randomizer->getBytesFromAlphabet(str_repeat('ab', $i), 500);
32+
$output = $randomizer->getBytesFromString(str_repeat('ab', $i), 500);
3333

3434
// This check can theoretically fail with a chance of 0.5**500.
3535
if (!str_contains($output, 'a') || !str_contains($output, 'b')) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Random: Randomizer: getBytesFromString(): Parameters are correctly validated
3+
--FILE--
4+
<?php
5+
6+
use Random\Randomizer;
7+
8+
function randomizer(): Randomizer
9+
{
10+
return new Randomizer();
11+
}
12+
13+
try {
14+
var_dump(randomizer()->getBytesFromString("", 2));
15+
} catch (ValueError $e) {
16+
echo $e->getMessage(), PHP_EOL;
17+
}
18+
19+
try {
20+
var_dump(randomizer()->getBytesFromString("abc", 0));
21+
} catch (ValueError $e) {
22+
echo $e->getMessage(), PHP_EOL;
23+
}
24+
25+
?>
26+
--EXPECTF--
27+
Random\Randomizer::getBytesFromString(): Argument #1 ($alphabet) cannot be empty
28+
Random\Randomizer::getBytesFromString(): Argument #2 ($length) must be greater than 0

0 commit comments

Comments
 (0)