-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBlockAppendTest.php
More file actions
72 lines (54 loc) · 1.71 KB
/
BlockAppendTest.php
File metadata and controls
72 lines (54 loc) · 1.71 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
<?php
declare(strict_types=1);
use HiFolks\DataType\Block;
use PHPUnit\Framework\TestCase;
final class BlockAppendTest extends TestCase
{
public function testAppendsJsons(): void
{
$data1 = Block::fromJsonFile(
__DIR__ . "/data/commits-json/commits-10-p1.json",
);
$data2 = Block::fromJsonFile(
__DIR__ . "/data/commits-json/commits-10-p2.json",
);
$data3 = Block::fromJsonFile(
__DIR__ . "/data/commits-json/commits-10-p3.json",
);
$this->assertCount(10, $data1);
$this->assertCount(10, $data2);
$data1->append($data2);
$this->assertCount(20, $data1);
$arrayData3 = $data3->toArray();
$this->assertIsArray($arrayData3);
$this->assertCount(10, $arrayData3);
$this->assertCount(20, $data1);
$data1->append($arrayData3);
$this->assertCount(30, $data1);
}
public function testAppendsArray(): void
{
$data1 = Block::make(["a", "b"]);
$arrayData2 = ["c", "d"];
$this->assertCount(2, $data1);
$data1->append($arrayData2);
$this->assertCount(4, $data1);
$this->assertSame(
["a", "b", "c", "d"],
array_values($data1->toArray()),
);
}
public function testAppendsItem(): void
{
$data1 = Block::make(["a", "b"]);
$arrayData2 = ["c", "d"];
$this->assertCount(2, $data1);
// appendItem adds the whole array as a single element
$data1->appendItem($arrayData2);
$this->assertCount(3, $data1);
$this->assertSame(
["a", "b", ["c", "d"]],
array_values($data1->toArray()),
);
}
}