From 5540bc760748b62239a7889e9e6dbef3a8e42581 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 17 Oct 2019 13:49:05 +0200 Subject: [PATCH] Add toString() method for String --- src/Symfony/Component/String/AbstractString.php | 5 +++++ .../Component/String/Tests/AbstractAsciiTestCase.php | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/Symfony/Component/String/AbstractString.php b/src/Symfony/Component/String/AbstractString.php index 9bbe348203..435363b798 100644 --- a/src/Symfony/Component/String/AbstractString.php +++ b/src/Symfony/Component/String/AbstractString.php @@ -589,6 +589,11 @@ abstract class AbstractString implements \JsonSerializable return new CodePointString($this->string); } + public function toString(): string + { + return $this->string; + } + public function toUnicodeString(): UnicodeString { return new UnicodeString($this->string); diff --git a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php index b7c0ac9229..934b29c148 100644 --- a/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php +++ b/src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php @@ -1370,4 +1370,11 @@ abstract class AbstractAsciiTestCase extends TestCase ['fo...', 'foobar', 5, '...'], ]; } + + public function testToString() + { + $instance = static::createFromString('foobar'); + + self::assertSame('foobar', $instance->toString()); + } }