| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * Test: Nette\Utils\Arrays::wrap()
- */
- declare(strict_types=1);
- use Nette\Utils\Arrays;
- use Tester\Assert;
- require __DIR__ . '/../bootstrap.php';
- test('Basics', function () {
- Assert::same([], Arrays::wrap([], '{', '}'));
- Assert::same(['STR'], Arrays::wrap(['STR']));
- Assert::same(['{STR'], Arrays::wrap(['STR'], '{'));
- Assert::same(['STR}'], Arrays::wrap(['STR'], '', '}'));
- Assert::same(['{STR}'], Arrays::wrap(['STR'], '{', '}'));
- });
- test('Type conversion', function () {
- $o = new class {
- public function __toString()
- {
- return 'toString';
- }
- };
- $cases = [
- [0, '0'],
- [1.1, '1.1'],
- [null, ''],
- [false, ''],
- [true, '1'],
- [$o, 'toString'],
- ];
- Assert::same(array_column($cases, 1), Arrays::wrap(array_column($cases, 0)));
- Assert::error(
- fn() => Arrays::wrap([[]]),
- PHP_VERSION_ID < 80000 ? E_NOTICE : E_WARNING,
- 'Array to string conversion',
- );
- });
|