public function testRandomBase64Safe()
{
$this->specify("base64Safe does not generate a valid string", function () {
$lens = [2, 12, 16, 24, 48, 100];
$random = new Random();
$isValid = function ($base64, $padding = false) {
$pattern = $padding ? "a-z0-9_=-" : "a-z0-9_-";
return preg_match("#[^{$pattern}]+#i", $base64) === 0;
};
foreach ($lens as $len) {
$actual = $random->base64Safe($len);
expect($isValid($actual))->true();
}
$actual = $random->base64Safe();
expect($isValid($actual))->true();
$actual = $random->base64Safe(null, true);
expect($isValid($actual, true))->true();
});
}