-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoderTest.php
More file actions
58 lines (44 loc) · 1.4 KB
/
Copy pathEncoderTest.php
File metadata and controls
58 lines (44 loc) · 1.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
<?php
namespace ToonLite\Tests;
use PHPUnit\Framework\TestCase;
use ToonLite\Encoder;
class EncoderTest extends TestCase
{
public function testEncodeSimpleObject(): void
{
$encoder = new Encoder();
$data = [
'id' => 1,
'name' => 'Manoj',
'active' => true,
];
$toon = $encoder->encode($data);
$this->assertStringContainsString('id: 1', $toon);
$this->assertStringContainsString('name: Manoj', $toon);
$this->assertStringContainsString('active: true', $toon);
}
public function testEncodePrimitiveArray(): void
{
$encoder = new Encoder();
$data = [
'tags' => ['php', 'ai', 'iot'],
];
$toon = $encoder->encode($data);
$this->assertSame("tags[3]: php,ai,iot\n", $toon);
}
public function testEncodeTabularArray(): void
{
$encoder = new Encoder();
$data = [
'items' => [
['sku' => 'A1', 'qty' => 2, 'price' => 9.99],
['sku' => 'B2', 'qty' => 1, 'price' => 14.5],
],
];
$toon = $encoder->encode($data);
$expectedHeader = "items[2]{sku,qty,price}:";
$this->assertStringContainsString($expectedHeader, $toon);
$this->assertStringContainsString("A1,2,9.99", $toon);
$this->assertStringContainsString("B2,1,14.5", $toon);
}
}