Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function validate(mixed $value, Constraint $constraint): void
return;
}

if (!\is_string($value)) {
if (!\is_string($value) && !$value instanceof \Stringable) {
throw new UnexpectedValueException($value, 'string');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function createValidator(): CharsetValidator
/**
* @dataProvider provideValidValues
*/
public function testEncodingIsValid(string $value, array $encodings)
public function testEncodingIsValid(string|\Stringable $value, array $encodings)
{
$this->validator->validate($value, new Charset(encodings: $encodings));

Expand Down Expand Up @@ -66,6 +66,12 @@ public static function provideValidValues()
yield ['my ûtf 8', ['ASCII', 'UTF-8']];
yield ['my ûtf 8', ['UTF-8']];
yield ['string', ['ISO-8859-1']];
yield [new class() implements \Stringable {
public function __toString(): string
{
return 'my ûtf 8';
}
}, ['UTF-8']];
}

public static function provideInvalidValues()
Expand Down