-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathValueTest.php
65 lines (54 loc) · 2.97 KB
/
ValueTest.php
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
<?php
/**
* This file is part of the phpCacheAdmin.
* Copyright (c) Róbert Kelčák (https://kelcak.com/)
*/
declare(strict_types=1);
namespace Tests;
use PHPUnit\Framework\TestCase;
use RobiNN\Pca\Value;
final class ValueTest extends TestCase {
public function testFormat(): void {
$value = '{"0":"test","test":"data"}';
$array = ['test', 'test' => 'data'];
$expected = '<pre class="json-code">{
"0": "test",
"test": "data"
}</pre>';
$this->assertEqualsCanonicalizing(['test', null, false], Value::format('test'));
$this->assertEqualsCanonicalizing([$expected, null, false], Value::format($value));
$this->assertEqualsCanonicalizing([$expected, 'gzcompress', false], Value::format(gzcompress($value)));
$this->assertEqualsCanonicalizing(['test', 'gzencode', false], Value::format(gzencode('test')));
$this->assertEqualsCanonicalizing([$expected, 'gzdeflate', true], Value::format(gzdeflate(serialize($array))));
$this->assertEqualsCanonicalizing([$expected, null, true], Value::format(serialize($array)));
}
public function testDecoded(): void {
$this->assertSame('gzcompress-data', Value::decoded(gzcompress('gzcompress-data')));
$this->assertSame('gzencode-data', Value::decoded(gzencode('gzencode-data')));
$this->assertSame('gzdeflate-data', Value::decoded(gzdeflate('gzdeflate-data')));
$this->assertSame('random string', Value::decoded('random string'));
}
public function testFormatted(): void {
$this->assertSame('{"0":"test","test":"data"}', Value::formatted(serialize(['test', 'test' => 'data'])));
$this->assertSame('random string', Value::formatted('random string'));
}
public function testPrettyPrintJson(): void {
$this->assertSame('1', Value::prettyPrintJson('1'));
$this->assertSame('data', Value::prettyPrintJson('data'));
$this->assertSame('<pre class="json-code">{
"0": "test",
"test": "data"
}</pre>', Value::prettyPrintJson('{"0":"test","test":"data"}'));
}
public function testEncode(): void {
$this->assertSame(gzcompress('gzcompress-data'), Value::converter('gzcompress-data', 'gzcompress', 'save'));
$this->assertSame(gzencode('gzencode-data'), Value::converter('gzencode-data', 'gzencode', 'save'));
$this->assertSame(gzdeflate('gzdeflate-data'), Value::converter('gzdeflate-data', 'gzdeflate', 'save'));
}
public function testDecode(): void {
$this->assertSame('gzcompress-data', Value::converter(gzcompress('gzcompress-data'), 'gzcompress', 'view'));
$this->assertSame('gzencode-data', Value::converter(gzencode('gzencode-data'), 'gzencode', 'view'));
$this->assertSame('gzdeflate-data', Value::converter(gzdeflate('gzdeflate-data'), 'gzdeflate', 'view'));
$this->assertSame('random string', Value::converter('random string', 'gzdeflate', 'view'));
}
}