Pantheon\Terminus\Commands\Self\ClearCacheCommand::clearCache PHP Method

clearCache() public method

Clear the local Terminus session and all saved machine tokens
public clearCache ( )
    public function clearCache()
    {
        $tokens = $this->session()->getTokens();
        $tokens->deleteAll();
        $this->session()->destroy();
        $this->log()->notice('Your saved machine tokens have been deleted and you have been logged out.');
    }

Usage Example

 /**
  * Tests the self:clear-cache commadn
  */
 public function testClearCache()
 {
     $this->session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
     $token = $this->getMockBuilder(SavedToken::class)->disableOriginalConstructor()->getMock();
     $token->expects($this->once())->method('delete');
     $token2 = $this->getMockBuilder(SavedToken::class)->disableOriginalConstructor()->getMock();
     $token2->expects($this->once())->method('delete');
     $tokens = $this->getMockBuilder(SavedTokens::class)->disableOriginalConstructor()->setMethods(['getMembers'])->getMock();
     $tokens->expects($this->any())->method('getMembers')->willReturn([$token, $token2]);
     $this->session->expects($this->any())->method('getTokens')->willReturn($tokens);
     $this->session->expects($this->once())->method('destroy');
     $this->logger->expects($this->once())->method('log')->with($this->equalTo('notice'), $this->equalTo('Your saved machine tokens have been deleted and you have been logged out.'));
     $command = new ClearCacheCommand();
     $command->setConfig($this->config);
     $command->setLogger($this->logger);
     $command->setSession($this->session);
     $command->clearCache();
 }
ClearCacheCommand