You are here

public function UnitTestCase::getStringTranslationStub in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getStringTranslationStub()

Returns a stub translation manager that just returns the passed string.

Return value

\PHPUnit\Framework\MockObject\MockObject|\Drupal\Core\StringTranslation\TranslationInterface A mock translation object.

49 calls to UnitTestCase::getStringTranslationStub()
AggregatorPluginSettingsBaseTest::setUp in core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
BaseFieldDefinitionTestBase::setUp in core/tests/Drupal/Tests/Core/Field/BaseFieldDefinitionTestBase.php
BlockManagerTest::setUp in core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php
BookManagerTest::setUp in core/modules/book/tests/src/Unit/BookManagerTest.php
BookUninstallValidatorTest::setUp in core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php

... See full list

File

core/tests/Drupal/Tests/UnitTestCase.php, line 217

Class

UnitTestCase
Provides a base class and helpers for Drupal unit tests.

Namespace

Drupal\Tests

Code

public function getStringTranslationStub() {
  $translation = $this
    ->createMock('Drupal\\Core\\StringTranslation\\TranslationInterface');
  $translation
    ->expects($this
    ->any())
    ->method('translate')
    ->willReturnCallback(function ($string, array $args = [], array $options = []) use ($translation) {
    return new TranslatableMarkup($string, $args, $options, $translation);
  });
  $translation
    ->expects($this
    ->any())
    ->method('translateString')
    ->willReturnCallback(function (TranslatableMarkup $wrapper) {
    return $wrapper
      ->getUntranslatedString();
  });
  $translation
    ->expects($this
    ->any())
    ->method('formatPlural')
    ->willReturnCallback(function ($count, $singular, $plural, array $args = [], array $options = []) use ($translation) {
    $wrapper = new PluralTranslatableMarkup($count, $singular, $plural, $args, $options, $translation);
    return $wrapper;
  });
  return $translation;
}