-
-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathReferencesTest.php
More file actions
87 lines (68 loc) · 2.4 KB
/
ReferencesTest.php
File metadata and controls
87 lines (68 loc) · 2.4 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types = 1);
namespace Gettext\Tests;
use Gettext\References;
use PHPUnit\Framework\TestCase;
class ReferencesTest extends TestCase
{
public function testReferences(): void
{
$references = new References();
$this->assertSame([], $references->jsonSerialize());
$this->assertCount(0, $references);
$references->add('filename.php', 34);
$this->assertSame(['filename.php' => [34]], $references->jsonSerialize());
$this->assertCount(1, $references);
$references->add('filename.php', 34);
$this->assertSame(['filename.php' => [34]], $references->jsonSerialize());
$this->assertCount(1, $references);
$references->add('filename.php', 44);
$this->assertSame(['filename.php' => [34, 44]], $references->jsonSerialize());
$this->assertCount(2, $references);
foreach ($references as $filename => $lines) {
$this->assertSame('filename.php', $filename);
$this->assertSame([34, 44], $lines);
}
}
public function testMergeReferences(): void
{
$references1 = new References();
$references2 = new References();
$references1
->add('filename.php', 34)
->add('filename.php', 56)
->add('filename3.php')
->add('filename2.php', 10);
$references2
->add('filename.php', 34)
->add('filename.php', 44)
->add('filename2.php')
->add('filename4.php')
->add('filename3.php', 10)
->add('5', 10)
->add('6');
$merged = $references1->mergeWith($references2);
$this->assertCount(8, $merged);
$this->assertSame([
'filename.php' => [34, 56, 44],
'filename3.php' => [10],
'filename2.php' => [10],
'filename4.php' => [],
'5' => [10],
'6' => [],
], $merged->toArray());
$this->assertNotSame($merged, $references1);
$this->assertNotSame($merged, $references2);
}
public function testCreateFromState(): void
{
$state = [
'references' => [
'filename.php' => [1, 2, 3],
],
];
$references = References::__set_state($state);
$this->assertCount(3, $references);
$this->assertSame($state['references'], $references->toArray());
}
}