Fixed type error when using Hyperf\Validation\Rules\Unique::__toString() in PHP8. (#3969)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
Kids Return 2021-08-23 15:38:19 +08:00 committed by GitHub
parent fb2a0536d1
commit cf1bc96e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# v2.2.6 - TBD
## Fixed
- [#3969](https://github.com/hyperf/hyperf/pull/3969) Fixed type error when using `Hyperf\Validation\Rules\Unique::__toString()` in PHP8.
# v2.2.5 - 2021-08-23
## Fixed

View File

@ -159,7 +159,7 @@ trait DatabaseRule
protected function formatWheres(): string
{
return collect($this->wheres)->map(function ($where) {
return $where['column'] . ',' . '"' . str_replace('"', '""', $where['value']) . '"';
return $where['column'] . ',' . '"' . str_replace('"', '""', (string) $where['value']) . '"';
})->implode(',');
}
}

View File

@ -59,6 +59,10 @@ class ValidationUniqueRuleTest extends TestCase
$rule = new Unique('table');
$rule->where('foo', '"bar"');
$this->assertEquals('unique:table,NULL,NULL,id,foo,"""bar"""', (string) $rule);
$rule = new Unique('table');
$rule->where('foo', 1);
$this->assertEquals('unique:table,NULL,NULL,id,foo,"1"', (string) $rule);
}
}