Exemplo n.º 1
0
<?php

use Humps\MailManager\Factories\ImapFactory;
use Humps\MailManager\ImapMailboxService;
require_once '../vendor/autoload.php';
$folder = isset($_REQUEST['folder']) ? $_REQUEST['folder'] : 'INBOX';
$imap = ImapFactory::create();
$mailboxService = new ImapMailboxService($imap);
$mailboxService->emptyTrash();
$message = "Trash Successfully Emptied";
header('Location:index.php?folder=' . $folder . '&success=' . $message);
 /**
  * @test
  */
 public function it_deletes_all_messages_from_the_trash_mailbox()
 {
     $imap = $this->getImap();
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->mailbox->shouldReceive('setFolder')->once()->with('INBOX.Trash');
     /** @noinspection PhpMethodParametersCountMismatchInspection */
     $this->mailbox->shouldReceive('setFolder')->once()->with('INBOX');
     /** @noinspection PhpUndefinedMethodInspection */
     $this->mailbox->shouldReceive('getFolder')->andReturn('INBOX');
     /** @noinspection PhpUndefinedMethodInspection */
     $imap->shouldReceive('deleteMessages')->andReturn(true);
     /** @noinspection PhpUndefinedMethodInspection */
     $imap->shouldReceive('setMessagesForDeletion')->with('1:*')->andReturn(true);
     /** @noinspection PhpUndefinedMethodInspection */
     $imap->shouldReceive('getMailbox')->andReturn($this->mailbox);
     /** @noinspection PhpUndefinedMethodInspection */
     $this->connection->shouldReceive('refresh')->andReturn(true);
     $mailboxManager = new ImapMailboxService($imap, __DIR__ . '/imap_config/config.php');
     $deleted = $mailboxManager->emptyTrash();
     $this->assertTrue($deleted);
     /** @noinspection PhpUndefinedMethodInspection */
     $imap->shouldHaveReceived('deleteMessages')->once();
     $this->mailbox->shouldHaveReceived('setFolder')->twice();
     /** @noinspection PhpUndefinedMethodInspection */
     $imap->shouldNotHaveReceived('close');
 }