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