Skip to content

Commit

Permalink
Fixed trimming null raising TypeError; now returns empty string.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Dec 14, 2024
1 parent 45aa554 commit 7292fdb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Strategy/Trim.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
10 changes: 10 additions & 0 deletions test/Integration/Mapper/Strategy/TrimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]));
}
}

0 comments on commit 7292fdb

Please sign in to comment.