$length * * @throws Exception * * @dataProvider lengthAndHexDataProvider * @runInSeparateProcess * @preserveGlobalState disabled */ public function testGenerateReturnsRandomBytes(int $length, string $hex): void { $bytes = hex2bin($hex); PHPMockery::mock('Ramsey\Uuid\Generator', 'random_bytes') ->once() ->with($length) ->andReturn($bytes); $generator = new RandomBytesGenerator(); $this->assertSame($bytes, $generator->generate($length)); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testGenerateThrowsExceptionWhenExceptionThrownByRandombytes(): void { PHPMockery::mock('Ramsey\Uuid\Generator', 'random_bytes') ->once() ->with(16) ->andThrow(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); } }