diff --git a/src/Strategy/Trim.php b/src/Strategy/Trim.php index a79b505..5b590c7 100644 --- a/src/Strategy/Trim.php +++ b/src/Strategy/Trim.php @@ -7,6 +7,6 @@ class Trim extends Delegate { public function __invoke($data, $context = null) { - return trim(parent::__invoke($data, $context)); + return trim((string)parent::__invoke($data, $context)); } } diff --git a/test/Integration/Mapper/Strategy/TrimTest.php b/test/Integration/Mapper/Strategy/TrimTest.php index 678f209..dbd9bc6 100644 --- a/test/Integration/Mapper/Strategy/TrimTest.php +++ b/test/Integration/Mapper/Strategy/TrimTest.php @@ -18,4 +18,14 @@ public function test(): void self::assertSame('foo', $trim([])); } + + /** + * Tests that trimming null returns the empty string. + */ + public function testNull(): void + { + $trim = (new Trim(null))->setMapper(new Mapper()); + + self::assertSame('', $trim([])); + } }