public function UnitTestCase::getStringTranslationStub in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/UnitTestCase.php \Drupal\Tests\UnitTestCase::getStringTranslationStub()
- 9 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.
43 calls to UnitTestCase::getStringTranslationStub()
- BaseFieldDefinitionTestBase::setUp in core/
tests/ Drupal/ Tests/ Core/ Field/ BaseFieldDefinitionTestBase.php - BlockManagerTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Block/ BlockManagerTest.php - CategorizingPluginManagerTraitTest::setUp in core/
tests/ Drupal/ Tests/ Core/ Plugin/ CategorizingPluginManagerTraitTest.php - CommentBulkFormTest::testConstructor in core/
modules/ comment/ tests/ src/ Unit/ Plugin/ views/ field/ CommentBulkFormTest.php - Tests the constructor assignment of actions.
- ContentTranslationLocalTasksTest::setUp in core/
modules/ content_translation/ tests/ src/ Unit/ Menu/ ContentTranslationLocalTasksTest.php
File
- core/
tests/ Drupal/ Tests/ UnitTestCase.php, line 198
Class
- UnitTestCase
- Provides a base class and helpers for Drupal unit tests.
Namespace
Drupal\TestsCode
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;
}