Skip to content

Commit 7292fdb

Browse files
committed
Fixed trimming null raising TypeError; now returns empty string.
1 parent 45aa554 commit 7292fdb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Strategy/Trim.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class Trim extends Delegate
77
{
88
public function __invoke($data, $context = null)
99
{
10-
return trim(parent::__invoke($data, $context));
10+
return trim((string)parent::__invoke($data, $context));
1111
}
1212
}

test/Integration/Mapper/Strategy/TrimTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ public function test(): void
1818

1919
self::assertSame('foo', $trim([]));
2020
}
21+
22+
/**
23+
* Tests that trimming null returns the empty string.
24+
*/
25+
public function testNull(): void
26+
{
27+
$trim = (new Trim(null))->setMapper(new Mapper());
28+
29+
self::assertSame('', $trim([]));
30+
}
2131
}

0 commit comments

Comments
 (0)