assertSame($bytes, $generator->generate($length)); $openSsl->verifyInvokedOnce([$length]); } /** * @throws Exception * * @dataProvider lengthAndHexDataProvider * @runInSeparateProcess * @preserveGlobalState disabled */ public function testGenerateReturnsRandomBytes(int $length, string $hex): void { $bytes = hex2bin($hex); AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', $bytes); $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); } }