function StringTranslationTraitTest::setUp

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest::setUp()
  2. 8.9.x core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest::setUp()
  3. 11.x core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php \Drupal\Tests\Core\StringTranslation\StringTranslationTraitTest::setUp()

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php, line 28

Class

StringTranslationTraitTest
@coversDefaultClass \Drupal\Core\StringTranslation\StringTranslationTrait @group StringTranslation

Namespace

Drupal\Tests\Core\StringTranslation

Code

protected function setUp() : void {
    parent::setUp();
    // Prepare a mock translation service to pass to the trait.
    $translation = $this->prophesize(TranslationInterface::class);
    $translation->translate(Argument::cetera())
        ->shouldNotBeCalled();
    $translation->formatPlural(Argument::cetera())
        ->shouldNotBeCalled();
    $translation->translateString(Argument::cetera())
        ->will(function ($args) {
        return $args[0]->getUntranslatedString();
    });
    // Set up the object under test.
    $this->testObject = new class  {
        use StringTranslationTrait;

};
    $this->testObject
        ->setStringTranslation($translation->reveal());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.