secureRandom = $this->getMockBuilder(ISecureRandom::class)->getMock(); $this->tokenHandler = new TokenHandler($this->secureRandom); } public function testGenerateToken(): void { $this->secureRandom->expects($this->once())->method('generate') ->with( $this->expectedTokenLength, ISecureRandom::CHAR_ALPHANUMERIC ) ->willReturn('mytoken'); $this->assertSame('mytoken', $this->tokenHandler->generateToken()); } }