Skip to content

Commit ffb7f0e

Browse files
committed
minor symfony#38304 [Translation] Allow Translatable objects to be used as strings (tgalopin)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Translation] Allow Translatable objects to be used as strings | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Allow Translatable objects to be used as strings. Commits ------- 0ba2064 [Translation] Allow Translatable objects to be used as strings
2 parents 6a55715 + 0ba2064 commit ffb7f0e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Symfony/Component/Translation/Tests/TranslatableTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testTrans($expected, $translatable, $translation, $locale)
2727
$translator->addLoader('array', new ArrayLoader());
2828
$translator->addResource('array', [$translatable->getMessage() => $translation], $locale, $translatable->getDomain());
2929

30-
$this->assertEquals($expected, Translatable::trans($translator, $translatable, $locale));
30+
$this->assertSame($expected, Translatable::trans($translator, $translatable, $locale));
3131
}
3232

3333
/**
@@ -39,7 +39,12 @@ public function testFlattenedTrans($expected, $messages, $translatable)
3939
$translator->addLoader('array', new ArrayLoader());
4040
$translator->addResource('array', $messages, 'fr', '');
4141

42-
$this->assertEquals($expected, Translatable::trans($translator, $translatable, 'fr'));
42+
$this->assertSame($expected, Translatable::trans($translator, $translatable, 'fr'));
43+
}
44+
45+
public function testToString()
46+
{
47+
$this->assertSame('Symfony is great!', (string) new Translatable('Symfony is great!'));
4348
}
4449

4550
public function getTransTests()

src/Symfony/Component/Translation/Translatable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public function __construct(string $message, array $parameters = [], string $dom
2929
$this->domain = $domain;
3030
}
3131

32+
public function __toString(): string
33+
{
34+
return $this->message;
35+
}
36+
3237
public function getMessage(): string
3338
{
3439
return $this->message;

0 commit comments

Comments
 (0)