You are here

protected function SMTPMailSystemTest::setUp in SMTP Authentication Support 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php, line 38

Class

SMTPMailSystemTest
Validate requirements for SMTPMailSystem.

Namespace

Drupal\Tests\smtp\Unit\Plugin\Mail

Code

protected function setUp() {
  $this->mockConfigFactory = $this
    ->getConfigFactoryStub([
    'smtp.settings' => [
      'smtp_timeout' => 30,
      'smtp_reroute_address' => '',
    ],
    'system.site' => [
      'name' => 'Mock site name',
    ],
  ]);
  $this->mockConfigFactoryRerouted = $this
    ->getConfigFactoryStub([
    'smtp.settings' => [
      'smtp_reroute_address' => 'blackhole@galaxy.com',
    ],
  ]);
  $this->mockLogger = $this
    ->prophesize(LoggerChannelFactoryInterface::class);
  $this->mockLogger
    ->get('smtp')
    ->willReturn($this
    ->prophesize(LoggerChannelInterface::class));
  $this->mockMessenger = $this
    ->prophesize(Messenger::class);
  $this->mockCurrentUser = $this
    ->prophesize(AccountProxy::class);
  $this->mockFileSystem = $this
    ->prophesize(FileSystem::class);
  $this->mimeTypeGuesser = $this
    ->prophesize(MimeTypeGuesser::class);
  $mockContainer = $this->mockContainer = $this
    ->prophesize(ContainerInterface::class);
  $mockContainer
    ->get('config.factory')
    ->willReturn($this->mockConfigFactory);
  $mockContainer
    ->get('logger.factory')
    ->willReturn($this->mockLogger
    ->reveal());
  $mockContainer
    ->get('messenger')
    ->willReturn($this->mockMessenger
    ->reveal());
  $mockContainer
    ->get('current_user')
    ->willReturn($this->mockCurrentUser
    ->reveal());
  $mockContainer
    ->get('file_system')
    ->willReturn($this->mockFileSystem
    ->reveal());
  $mockContainer
    ->get('file.mime_type.guesser')
    ->willReturn($this->mimeTypeGuesser
    ->reveal());
  $mockStringTranslation = $this
    ->prophesize(TranslationInterface::class);
  $mockStringTranslation
    ->translate(Argument::any())
    ->willReturnArgument(0);
  $mockStringTranslation
    ->translate(Argument::any(), Argument::any())
    ->willReturnArgument(0);
  $mockStringTranslation
    ->translateString(Argument::any())
    ->willReturn('.');
  $mockContainer
    ->get('string_translation')
    ->willReturn($mockStringTranslation
    ->reveal());

  // Email validator.
  $this->emailValidator = new EmailValidator();
  $mockContainer
    ->get('email.validator')
    ->willReturn($this->emailValidator);
  \Drupal::setContainer($this->mockContainer
    ->reveal());
}