-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncoderInterfaceTest.php
More file actions
72 lines (52 loc) · 1.97 KB
/
EncoderInterfaceTest.php
File metadata and controls
72 lines (52 loc) · 1.97 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 PHPUnit\Framework\TestCase;
use MicroEncode\HtmlEncoder;
use MicroEncode\XmlEncoder;
final class EncoderInterfaceTest extends TestCase {
public static function randString(int $len,string $char_pool="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") : string {
$charPoolIdxCeil=strlen($char_pool)-1;
$randString="";
for($i=0;$i<$len;$i++) {
$randString .= $char_pool[mt_rand(0,$charPoolIdxCeil)];
}
return $randString;
}
public static function randStringStartingWithAlpha(int $len) : string {
return static::randString(1,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ").static::randString($len-1);
}
const SAMPLE_DATA_COUNT = 10;
const SAMPLE_DATA_PROPERTY_COUNT = 50;
const SAMPLE_DATA_PROPERTY_VALUE_LEN = 100;
public function sampleDataProvider() : array {
$dataSet = [];
for($i=0;$i<static::SAMPLE_DATA_COUNT;$i++) {
$data = [];
for($p=0;$p<static::SAMPLE_DATA_PROPERTY_COUNT;$p++) {
for(;;) {
$propName = static::randStringStartingWithAlpha($p+10);
if (!isset($data[$propName])) {
$data[$propName] = static::randString(static::SAMPLE_DATA_PROPERTY_VALUE_LEN);
break 1;
}
}
}
$dataSet[] = [(object) $data];
}
return $dataSet;
}
/**
* @dataProvider sampleDataProvider
*/
public function testXmlEncodedValueMatchesMagicStringMethod($data) {
$xmlEncoder = new XmlEncoder($data);
$this->assertEquals($xmlEncoder->__toString(), $xmlEncoder->getEncodedValue());
}
/**
* @dataProvider sampleDataProvider
*/
public function testHtmlEncodedValueMatchesMagicStringMethod($data) {
$htmlEncoder = new HtmlEncoder($data);
$this->assertEquals($htmlEncoder->__toString(), $htmlEncoder->getEncodedValue());
}
}