-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEncoderTest.php
More file actions
95 lines (79 loc) · 2.78 KB
/
Copy pathEncoderTest.php
File metadata and controls
95 lines (79 loc) · 2.78 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
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
namespace GlobusStudio\QRCode\Tests\Unit\Encoder;
use GlobusStudio\QRCode\Encoder\Encoder;
use GlobusStudio\QRCode\ErrorCorrection\ErrorCorrectionLevel;
use PHPUnit\Framework\TestCase;
final class EncoderTest extends TestCase
{
public function testEncodeNumericData(): void
{
$matrix = Encoder::encode('12345', ErrorCorrectionLevel::L);
self::assertSame(21, count($matrix));
self::assertSame(21, count($matrix[0]));
}
public function testEncodeAlphanumericData(): void
{
$matrix = Encoder::encode('HELLO', ErrorCorrectionLevel::M);
self::assertSame(21, count($matrix));
}
public function testEncodeByteData(): void
{
$matrix = Encoder::encode('hello world', ErrorCorrectionLevel::M);
self::assertSame(21, count($matrix));
}
public function testEncodeWithHighErrorCorrection(): void
{
$matrix = Encoder::encode('test', ErrorCorrectionLevel::H);
self::assertSame(21, count($matrix));
}
public function testModuleCountFormula(): void
{
$matrix = Encoder::encode('A', ErrorCorrectionLevel::L, 1);
self::assertSame(21, count($matrix));
$matrix = Encoder::encode('A', ErrorCorrectionLevel::L, 2);
self::assertSame(25, count($matrix));
}
public function testEncodeLongData(): void
{
$data = str_repeat('A', 100);
$matrix = Encoder::encode($data, ErrorCorrectionLevel::L);
self::assertGreaterThan(21, count($matrix));
}
public function testEncodeWithExplicitVersion(): void
{
$matrix = Encoder::encode('TEST', ErrorCorrectionLevel::M, 5);
$expected = 5 * 4 + 17;
self::assertSame($expected, count($matrix));
}
public function testMatrixContainsBooleans(): void
{
$matrix = Encoder::encode('test', ErrorCorrectionLevel::M);
foreach ($matrix as $row) {
foreach ($row as $cell) {
self::assertIsBool($cell);
}
}
}
public function testInvalidErrorCorrectionLevel(): void
{
$this->expectException(\InvalidArgumentException::class);
Encoder::encode('test', 99);
}
public function testVersion7HasTypeNumber(): void
{
$matrix = Encoder::encode('A', ErrorCorrectionLevel::L, 7);
$expected = 7 * 4 + 17;
self::assertSame($expected, count($matrix));
}
public function testEncodeUrl(): void
{
$matrix = Encoder::encode('https://example.com', ErrorCorrectionLevel::M);
self::assertGreaterThanOrEqual(21, count($matrix));
}
public function testDataOverflowThrows(): void
{
$this->expectException(\OverflowException::class);
Encoder::encode(str_repeat('A', 500), ErrorCorrectionLevel::H, 1);
}
}