-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathArrays.updateDiff().phpt
More file actions
71 lines (53 loc) · 1.2 KB
/
Arrays.updateDiff().phpt
File metadata and controls
71 lines (53 loc) · 1.2 KB
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
<?php
/**
* Test: Nette\Utils\Arrays::updateDiff()
*/
declare(strict_types=1);
use Nette\Utils\Arrays;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
test('Basics', function () {
Assert::same([], Arrays::updateDiff([], []));
Assert::same([], Arrays::updateDiff(['a' => ''], []));
});
test('New keys', function () {
$to = [
'a' => null,
'b' => false,
'c' => '',
'd' => 0,
];
Assert::same($to, Arrays::updateDiff([], $to));
});
test('To falsy values', function () {
$from = [
'a' => null,
'b' => false,
'c' => '',
'd' => 0,
];
$toNull = ['a' => null, 'b' => null, 'c' => null, 'd' => null];
Assert::same([
'b' => null,
'c' => null,
'd' => null,
], Arrays::updateDiff($from, $toNull));
$toFalse = ['a' => false, 'b' => false, 'c' => false, 'd' => false];
Assert::same([
'a' => false,
'c' => false,
'd' => false,
], Arrays::updateDiff($from, $toFalse));
$toEmpty = ['a' => '', 'b' => '', 'c' => '', 'd' => ''];
Assert::same([
'a' => '',
'b' => '',
'd' => '',
], Arrays::updateDiff($from, $toEmpty));
$toZero = ['a' => 0, 'b' => 0, 'c' => 0, 'd' => 0];
Assert::same([
'a' => 0,
'b' => 0,
'c' => 0,
], Arrays::updateDiff($from, $toZero));
});