<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

use Kufer\Mail\Sender\Result\EMailSentResult;
use Kufer\Mail\Sender\Result\EMailSentRecipient;
use Kufer\Mail\Sender\Result\EMailSentStatusCode;

class EMailSentResultTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var array {@link \Kufer\Mail\Address\IEMailAddress}
   */
  protected $addresses;

  /**
   *
   * @var array
   */
  protected $recipients;

  /**
   * @var EMailSentResult
   */
  protected $obj1;

  public function setUp(): void
  {
    $this->addresses = array(
        new \Kufer\Mail\Address\EMailAddress('Test 1', 'test1@example.org'),
        new \Kufer\Mail\Address\EMailAddress('Test 2', 'test2@example.org'),
        new \Kufer\Mail\Address\EMailAddress('Test 3', 'test3@example.org')
    );

    $this->recipients = array(
      'test0' => new EMailSentRecipient(EMailSentStatusCode::SUCCESSFULL, $this->addresses[0], 'Test'),
      'test1' => new EMailSentRecipient(EMailSentStatusCode::SUCCESSFULL, $this->addresses[1], 'Test'),
      'test2' => new EMailSentRecipient(EMailSentStatusCode::SUCCESSFULL, $this->addresses[2], 'Test')
    );

    $this->obj1 = new EMailSentResult(\array_merge(
      \array_map(function($i) {
        return new EMailSentRecipient(
          EMailSentStatusCode::SUCCESSFULL,
          new \Kufer\Mail\Address\EMailAddress('Test ' . $i, 'test' . $i . '@example.org'),
          'Test'
        );
      }, \range(0, 2)),
      \array_map(function($i) {
        return new EMailSentRecipient(
          EMailSentStatusCode::WARNING_EMAIL_SENDER_NOT_FOUND,
          new \Kufer\Mail\Address\EMailAddress('Test ' . $i, 'test' . $i . '@example.org'),
          'Test'
        );
      }, \range(0, 3)),
      \array_map(function($i) {
        return new EMailSentRecipient(
          EMailSentStatusCode::FAILURE_EMAIL_NOT_FOUND,
          new \Kufer\Mail\Address\EMailAddress('Test ' . $i, 'test' . $i . '@example.org'),
          'Test'
        );
      }, \range(0, 1)),
      \array_map(function($i) {
        return new EMailSentRecipient(
          EMailSentStatusCode::FAILURE_UNKNOWN_ERROR,
          new \Kufer\Mail\Address\EMailAddress('Test ' . $i, 'test' . $i . '@example.org'),
          'Test'
        );
      }, \range(0, 4))
    ));
  }

  public function tearDown(): void
  {
  }

  /**
   * @test
   * @covers EMailSentResult::getRecipients
   */
  public function getRecipient_Recipients_Equals()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertEquals($this->recipients, $obj0->getRecipients());
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueSuccessMessages
   */
  public function getUniqueSuccessMessages_Equals1()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertEquals(1, \count($obj0->getUniqueSuccessMessages()));
  }

  /**
   * @test
   * @covers EMailSentResult::getSuccessMessagesWithNames
   */
  public function getSuccessMessagesWithNames_Equals3()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertEquals(3, \count($obj0->getSuccessMessagesWithNames()));
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueWarningMessages
   */
  public function getUniqueWarningMessages_Equals0()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertEquals(0, \count($obj0->getUniqueWarningMessages()));
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueErrorMessages
   */
  public function getUniqueErrorMessages_Equals0()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertEquals(0, \count($obj0->getUniqueErrorMessages()));
  }

  /**
   * @test
   * @covers EMailSentResult::hasSentAllMails
   */
  public function hasSentAllMails_All3Success_true()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertTrue($obj0->hasSentAllMails());
  }

  /**
   * @test
   * @covers EMailSentResult::hasSentAnyMails
   */
  public function hasSentAnyMails_All3Success_true()
  {
    $obj0 = new EMailSentResult($this->recipients);
    $this->assertTrue($obj0->hasSentAllMails());
  }

  /**
   * @test
   * @covers EMailSentResult::hasSentAllMails
   */
  public function hasSentAllMails_Object1_false()
  {
    $this->assertFalse($this->obj1->hasSentAllMails());
  }

  /**
   * @test
   * @covers EMailSentResult::hasSentAnyMails
   */
  public function hasSentAnyMails_Object1_true()
  {
    $this->assertTrue($this->obj1->hasSentAnyMails());
  }

  /**
   * @test
   * @covers EMailSentResult::getSuccess
   */
  public function getSuccess_Object1_Equals3()
  {
    $this->assertEquals(3, \count($this->obj1->getSuccess()));
  }

  /**
   * @test
   * @covers EMailSentResult::getWarnings
   */
  public function getWarnings_Object1_Equals4()
  {
    $this->assertEquals(4, \count($this->obj1->getWarnings()));
  }

  /**
   * @test
   * @covers EMailSentResult::getErrors
   */
  public function getErrors_Object1_Equals7()
  {
    $this->assertEquals(7, \count($this->obj1->getErrors()));
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueSuccessMessages
   */
  public function getUniqueSuccessMessage_Object1_Equals1()
  {
    $this->assertEquals(1, \count($this->obj1->getUniqueSuccessMessages()));
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueSuccessMessages
   */
  public function getUniqueWarningMessages_Object1_Equals1()
  {
    $this->assertEquals(1, \count($this->obj1->getUniqueWarningMessages()));
  }

  /**
   * @test
   * @covers EMailSentResult::getUniqueErrorMessages
   */
  public function getUniqueErrorMessages_Object1_Equals1()
  {
    $this->assertEquals(1, \count($this->obj1->getUniqueErrorMessages()));
  }
}
