nonceGenerator = new NonceGenerator(); } /** * testGenerateMethodUnique check that the nonce generated is unique. */ public function testGenerateMethodUnique(): void { $nonces = []; // Generate a list of nonces for ($i = 0; $i < 10; ++$i) { $nonces[] = $this->nonceGenerator->generate(); } // Check that there are no duplicate values $this->assertCount(10, array_unique($nonces)); } /** * testGenerateMethodHexadecimal check that the nonce generated is a valid hexadecimal string. */ public function testGenerateMethodHexadecimal(): void { // Generate a nonce $nonce = $this->nonceGenerator->generate(); // Check that the nonce is a valid hexadecimal string $this->assertTrue(ctype_xdigit($nonce)); } /** * testGenerateMethodLength check that the nonce generated is indeed 32 characters long. */ public function testGenerateMethodLength(): void { // Generate a nonce $nonce = $this->nonceGenerator->generate(); // Check that the nonce is the correct length $this->assertSame(32, \strlen($nonce)); } }