|
22 | 22 | use Config\Filters; |
23 | 23 | use Config\Services; |
24 | 24 | use PHPUnit\Framework\Attributes\BackupGlobals; |
| 25 | +use PHPUnit\Framework\Attributes\DataProvider; |
25 | 26 | use PHPUnit\Framework\Attributes\Group; |
26 | 27 | use PHPUnit\Framework\Attributes\PreserveGlobalState; |
27 | 28 | use PHPUnit\Framework\Attributes\RunInSeparateProcess; |
28 | 29 | use PHPUnit\Framework\Attributes\WithoutErrorHandler; |
| 30 | +use Stringable; |
29 | 31 |
|
30 | 32 | /** |
31 | 33 | * @internal |
@@ -867,6 +869,38 @@ public function testSetValue(): void |
867 | 869 | $this->assertSame('baz', set_value('foo', 'baz')); |
868 | 870 | } |
869 | 871 |
|
| 872 | + #[DataProvider('provideSetValueCastsNonArrayDefaultToString')] |
| 873 | + public function testSetValueCastsNonArrayDefaultToString(mixed $default, string $expected): void |
| 874 | + { |
| 875 | + $this->assertSame($expected, set_value('foo', $default)); |
| 876 | + } |
| 877 | + |
| 878 | + /** |
| 879 | + * @return iterable<string, array{mixed, string}> |
| 880 | + */ |
| 881 | + public static function provideSetValueCastsNonArrayDefaultToString(): iterable |
| 882 | + { |
| 883 | + $stringable = self::createStub(Stringable::class); |
| 884 | + $stringable->method('__toString')->willReturn('<bar>'); |
| 885 | + |
| 886 | + yield 'int' => [1, '1']; |
| 887 | + |
| 888 | + yield 'float' => [1.5, '1.5']; |
| 889 | + |
| 890 | + yield 'true' => [true, '1']; |
| 891 | + |
| 892 | + yield 'false' => [false, '']; |
| 893 | + |
| 894 | + yield 'null' => [null, '']; |
| 895 | + |
| 896 | + yield 'stringable' => [$stringable, '<bar>']; |
| 897 | + } |
| 898 | + |
| 899 | + public function testSetValueKeepsArrayDefault(): void |
| 900 | + { |
| 901 | + $this->assertSame(['a', 'b'], set_value('foo', ['a', 'b'])); |
| 902 | + } |
| 903 | + |
870 | 904 | public function testSetSelect(): void |
871 | 905 | { |
872 | 906 | $_SESSION['_ci_old_input']['post']['foo'] = 'bar'; |
|
0 commit comments