File: Arrays.renameKey%28%29.phpt

package info (click to toggle)
php-nette-utils 4.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,420 kB
  • sloc: php: 4,069; xml: 12; makefile: 4
file content (80 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

/**
 * Test: Nette\Utils\Arrays::renameKey()
 */

declare(strict_types=1);

use Nette\Utils\Arrays;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$arr = [
	'' => 'first',
	0 => 'second',
	7 => 'fourth',
	1 => 'third',
];

Assert::true(Arrays::renameKey($arr, '1', 'new1'));
Assert::same([
	'' => 'first',
	0 => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Arrays::renameKey($arr, 0, 'new2');
Assert::same([
	'' => 'first',
	'new2' => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Arrays::renameKey($arr, '', 'new3');
Assert::same([
	'new3' => 'first',
	'new2' => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Arrays::renameKey($arr, '', 'new4');
Assert::same([
	'new3' => 'first',
	'new2' => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Assert::false(Arrays::renameKey($arr, 'undefined', 'new5'));
Assert::same([
	'new3' => 'first',
	'new2' => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Arrays::renameKey($arr, 'new2', 'new3');
Assert::same([
	'new3' => 'second',
	7 => 'fourth',
	'new1' => 'third',
], $arr);

Arrays::renameKey($arr, 'new3', 'new1');
Assert::same([
	'new1' => 'second',
	7 => 'fourth',
], $arr);

Assert::true(Arrays::renameKey($arr, 'new1', 'new1'));
Assert::same([
	'new1' => 'second',
	7 => 'fourth',
], $arr);