Skip to content

Commit 577ccb0

Browse files
committed
Ensure that toString returns a string when using integers. Use assertSame to have a stricter check.
1 parent e5a5860 commit 577ccb0

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/Fields/LabeledValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function label()
2828

2929
public function __toString()
3030
{
31-
return $this->value ?? '';
31+
return (string) $this->value ?? '';
3232
}
3333

3434
public function toArray()

tests/Fields/LabeledValueTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ function it_gets_the_label_and_value()
2121
/** @test */
2222
function it_converts_to_a_string()
2323
{
24-
$this->assertEquals('world', (string) new LabeledValue('world', 'World'));
25-
$this->assertEquals('', (string) new LabeledValue(null, null));
24+
$this->assertSame('world', (new LabeledValue('world', 'World'))->__toString());
25+
$this->assertSame('', (new LabeledValue(null, null))->__toString());
26+
$this->assertSame('4', (new LabeledValue(4, 'Four'))->__toString());
2627
}
2728

2829
/** @test */

0 commit comments

Comments
 (0)