mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
@@ -6,6 +6,7 @@ namespace Ramsey\Uuid\Test\Generator;
|
||||
|
||||
use AspectMock\Test as AspectMock;
|
||||
use Exception;
|
||||
use Ramsey\Uuid\Exception\RandomSourceException;
|
||||
use Ramsey\Uuid\Generator\RandomBytesGenerator;
|
||||
use Ramsey\Uuid\Test\TestCase;
|
||||
|
||||
@@ -54,4 +55,22 @@ class RandomBytesGeneratorTest extends TestCase
|
||||
$generator = new RandomBytesGenerator();
|
||||
$this->assertEquals($bytes, $generator->generate($length));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testGenerateThrowsExceptionWhenExceptionThrownByRandombytes(): void
|
||||
{
|
||||
AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', function (): void {
|
||||
throw new Exception('Could not gather sufficient random data');
|
||||
});
|
||||
|
||||
$generator = new RandomBytesGenerator();
|
||||
|
||||
$this->expectException(RandomSourceException::class);
|
||||
$this->expectExceptionMessage('Could not gather sufficient random data');
|
||||
|
||||
$generator->generate(16);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user