Skip to content

Commit c99f5d4

Browse files
committed
🛀 test overhaul
1 parent b9d2059 commit c99f5d4

36 files changed

+356
-333
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ parameters:
102102
count: 1
103103
path: examples/intervention-image.php
104104

105+
-
106+
rawMessage: 'Function parseHexValue() return type has no value type specified in iterable type array.'
107+
identifier: missingType.iterableValue
108+
count: 1
109+
path: examples/qrcode-interactive.php
110+
105111
-
106112
rawMessage: 'Method RandomDotsSVGOutput::collectModules() should return array<int, mixed> but returns array<int|string, list<string>>.'
107113
identifier: return.type
@@ -234,24 +240,12 @@ parameters:
234240
count: 1
235241
path: src/QRCode.php
236242

237-
-
238-
rawMessage: 'Method chillerlan\QRCodeTest\Common\MaskPatternTest::assertMask() has parameter $expected with no value type specified in iterable type array.'
239-
identifier: missingType.iterableValue
240-
count: 1
241-
path: tests/Common/MaskPatternTest.php
242-
243243
-
244244
rawMessage: 'Method chillerlan\QRCodeTest\Common\MaskPatternTest::maskPatternProvider() return type has no value type specified in iterable type array.'
245245
identifier: missingType.iterableValue
246246
count: 1
247247
path: tests/Common/MaskPatternTest.php
248248

249-
-
250-
rawMessage: 'Method chillerlan\QRCodeTest\Common\MaskPatternTest::testMask() has parameter $expected with no value type specified in iterable type array.'
251-
identifier: missingType.iterableValue
252-
count: 1
253-
path: tests/Common/MaskPatternTest.php
254-
255249
-
256250
rawMessage: 'Parameter #1 $string of static method chillerlan\QRCode\Data\QRDataModeInterface::validateString() expects string, string|false given.'
257251
identifier: argument.type

tests/Common/BitBufferTest.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use chillerlan\QRCode\QRCodeException;
1515
use chillerlan\QRCode\Common\{BitBuffer, Mode};
16-
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\Attributes\{Test, TestWith};
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
@@ -27,28 +27,21 @@ protected function setUp():void{
2727
$this->bitBuffer = new BitBuffer;
2828
}
2929

30-
/**
31-
* @phpstan-return array<string, array{0: int, 1: int}>
32-
*/
33-
public static function bitProvider():array{
34-
return [
35-
'number' => [Mode::NUMBER, 16],
36-
'alphanum' => [Mode::ALPHANUM, 32],
37-
'byte' => [Mode::BYTE, 64],
38-
'kanji' => [Mode::KANJI, 128],
39-
'hanzi' => [Mode::HANZI, 208],
40-
];
41-
}
42-
43-
#[DataProvider('bitProvider')]
44-
public function testPut(int $data, int $expected):void{
30+
#[Test]
31+
#[TestWith([Mode::NUMBER, 16], 'number')]
32+
#[TestWith([Mode::ALPHANUM, 32], 'alphanum')]
33+
#[TestWith([Mode::BYTE, 64], 'byte')]
34+
#[TestWith([Mode::KANJI, 128], 'kanji')]
35+
#[TestWith([Mode::HANZI, 208], 'hanzi')]
36+
public function put(int $data, int $expected):void{
4537
$this->bitBuffer->put($data, 4);
4638

4739
$this::assertSame($expected, $this->bitBuffer->getBuffer()[0]);
4840
$this::assertSame(4, $this->bitBuffer->getLength());
4941
}
5042

51-
public function testReadException():void{
43+
#[Test]
44+
public function readException():void{
5245
$this->expectException(QRCodeException::class);
5346
$this->expectExceptionMessage('invalid $numBits');
5447

tests/Common/ECICharsetTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@
1313

1414
use chillerlan\QRCode\QRCodeException;
1515
use chillerlan\QRCode\Common\ECICharset;
16-
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\Attributes\{DataProvider, Test, TestWith};
1717
use PHPUnit\Framework\TestCase;
1818

1919
final class ECICharsetTest extends TestCase{
2020

21-
/**
22-
* @phpstan-return array<int, array{0: int}>
23-
*/
24-
public static function invalidIdProvider():array{
25-
return [[-1], [1000000]];
26-
}
27-
28-
#[DataProvider('invalidIdProvider')]
29-
public function testInvalidDataException(int $id):void{
21+
#[Test]
22+
#[TestWith([-1])]
23+
#[TestWith([1000000])]
24+
public function invalidDataException(int $id):void{
3025
$this->expectException(QRCodeException::class);
3126
$this->expectExceptionMessage('invalid charset id:');
3227

@@ -46,8 +41,9 @@ public static function encodingProvider():array{
4641
return $params;
4742
}
4843

44+
#[Test]
4945
#[DataProvider('encodingProvider')]
50-
public function testGetName(int $id, string|null $name = null):void{
46+
public function getName(int $id, string|null $name = null):void{
5147
$eciCharset = new ECICharset($id);
5248

5349
$this::assertSame($id, $eciCharset->getID());

tests/Common/EccLevelTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,51 @@
1313

1414
use chillerlan\QRCode\QRCodeException;
1515
use chillerlan\QRCode\Common\{EccLevel, MaskPattern};
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718

1819
/**
1920
* EccLevel coverage test
2021
*/
2122
final class EccLevelTest extends TestCase{
2223

23-
public function testConstructInvalidEccException():void{
24+
#[Test]
25+
public function constructInvalidEccException():void{
2426
$this->expectException(QRCodeException::class);
2527
$this->expectExceptionMessage('invalid ECC level');
2628

2729
new EccLevel(69);
2830
}
2931

30-
public function testToString():void{
32+
#[Test]
33+
public function eccToString():void{
3134
$ecc = new EccLevel(EccLevel::L);
3235

3336
$this::assertSame('L', (string)$ecc);
3437
}
3538

36-
public function testGetLevel():void{
39+
#[Test]
40+
public function getLevel():void{
3741
$ecc = new EccLevel(EccLevel::L);
3842

3943
$this::assertSame(EccLevel::L, $ecc->getLevel());
4044
}
4145

42-
public function testGetOrdinal():void{
46+
#[Test]
47+
public function getOrdinal():void{
4348
$ecc = new EccLevel(EccLevel::L);
4449

4550
$this::assertSame(0, $ecc->getOrdinal());
4651
}
4752

48-
public function testGetformatPattern():void{
53+
#[Test]
54+
public function getformatPattern():void{
4955
$ecc = new EccLevel(EccLevel::Q);
5056

5157
$this::assertSame(0b010010010110100, $ecc->getformatPattern(new MaskPattern(4)));
5258
}
5359

60+
#[Test]
5461
public function getMaxBits():void{
5562
$ecc = new EccLevel(EccLevel::Q);
5663

tests/Common/MaskPatternTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use chillerlan\QRCode\QRCodeException;
1818
use chillerlan\QRCode\Common\MaskPattern;
19-
use PHPUnit\Framework\Attributes\DataProvider;
19+
use PHPUnit\Framework\Attributes\{DataProvider, Test};
2020
use PHPUnit\Framework\TestCase;
2121
use Closure;
2222

@@ -100,8 +100,9 @@ public static function maskPatternProvider():array{
100100
*
101101
* @param int[][] $expected
102102
*/
103+
#[Test]
103104
#[DataProvider('maskPatternProvider')]
104-
public function testMask(int $pattern, array $expected):void{
105+
public function mask(int $pattern, array $expected):void{
105106
$maskPattern = new MaskPattern($pattern);
106107

107108
$this::assertTrue($this->assertMask($maskPattern->getMask(), $expected));
@@ -126,14 +127,16 @@ private function assertMask(Closure $mask, array $expected):bool{
126127
/**
127128
* Tests if an exception is thrown on an incorrect mask pattern
128129
*/
129-
public function testInvalidMaskPatternException():void{
130+
#[Test]
131+
public function invalidMaskPatternException():void{
130132
$this->expectException(QRCodeException::class);
131133
$this->expectExceptionMessage('invalid mask pattern');
132134

133135
new MaskPattern(42);
134136
}
135137

136-
public function testPenaltyRule1():void{
138+
#[Test]
139+
public function penaltyRule1():void{
137140
// horizontal
138141
$this::assertSame(0, MaskPattern::testRule1([[false, false, false, false]], 1, 4));
139142
$this::assertSame(3, MaskPattern::testRule1([[false, false, false, false, false, true]], 1, 6));
@@ -144,14 +147,16 @@ public function testPenaltyRule1():void{
144147
$this::assertSame(4, MaskPattern::testRule1([[false], [false], [false], [false], [false], [false]], 6, 1));
145148
}
146149

147-
public function testPenaltyRule2():void{
150+
#[Test]
151+
public function penaltyRule2():void{
148152
$this::assertSame(0, MaskPattern::testRule2([[false]], 1, 1));
149153
$this::assertSame(0, MaskPattern::testRule2([[false, false], [false, true]], 2, 2));
150154
$this::assertSame(3, MaskPattern::testRule2([[false, false], [false, false]], 2, 2));
151155
$this::assertSame(12, MaskPattern::testRule2([[false, false, false], [false, false, false], [false, false, false]], 3, 3)); // phpcs:ignore
152156
}
153157

154-
public function testPenaltyRule3():void{
158+
#[Test]
159+
public function penaltyRule3():void{
155160
// horizontal
156161
$this::assertSame(40, MaskPattern::testRule3([[false, false, false, false, true, false, true, true, true, false, true]], 1, 11)); // phpcs:ignore
157162
$this::assertSame(40, MaskPattern::testRule3([[true, false, true, true, true, false, true, false, false, false, false]], 1, 11)); // phpcs:ignore
@@ -162,7 +167,8 @@ public function testPenaltyRule3():void{
162167
$this::assertSame(0, MaskPattern::testRule3([[true], [false], [true], [true], [true], [false], [true]], 7, 1));
163168
}
164169

165-
public function testPenaltyRule4():void{
170+
#[Test]
171+
public function penaltyRule4():void{
166172
$this::assertSame(100, MaskPattern::testRule4([[false]], 1, 1));
167173
$this::assertSame(0, MaskPattern::testRule4([[false, true]], 1, 2));
168174
$this::assertSame(30, MaskPattern::testRule4([[false, true, true, true, true, false]], 1, 6));

tests/Common/ModeTest.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use chillerlan\QRCode\QRCodeException;
1515
use chillerlan\QRCode\Common\Mode;
16-
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\Attributes\{Test, TestWith};
1717
use PHPUnit\Framework\TestCase;
1818

1919
/**
@@ -22,34 +22,29 @@
2222
final class ModeTest extends TestCase{
2323

2424
/**
25-
* version breakpoints for numeric mode
26-
*
27-
* @phpstan-return array<int, array{0: int, 1: int}>
25+
* Tests the version breakpoints for numeric mode
2826
*/
29-
public static function versionProvider():array{
30-
return [
31-
[ 1, 10],
32-
[ 9, 10],
33-
[10, 12],
34-
[26, 12],
35-
[27, 14],
36-
[40, 14],
37-
];
38-
}
39-
40-
#[DataProvider('versionProvider')]
41-
public function testGetLengthBitsForVersionBreakpoints(int $version, int $expected):void{
27+
#[Test]
28+
#[TestWith([ 1, 10], '10 low')]
29+
#[TestWith([ 9, 10], '10 high')]
30+
#[TestWith([10, 12], '12 low')]
31+
#[TestWith([26, 12], '12 high')]
32+
#[TestWith([27, 14], '14 low')]
33+
#[TestWith([40, 14], '14 high')]
34+
public function getLengthBitsForVersionBreakpoints(int $version, int $expected):void{
4235
$this::assertSame($expected, Mode::getLengthBitsForVersion(Mode::NUMBER, $version));
4336
}
4437

45-
public function testGetLengthBitsForVersionInvalidModeException():void{
38+
#[Test]
39+
public function getLengthBitsForVersionInvalidModeException():void{
4640
$this->expectException(QRCodeException::class);
4741
$this->expectExceptionMessage('invalid mode given');
4842

4943
Mode::getLengthBitsForVersion(42, 69);
5044
}
5145

52-
public function testGetLengthBitsForVersionInvalidVersionException():void{
46+
#[Test]
47+
public function getLengthBitsForVersionInvalidVersionException():void{
5348
$this->expectException(QRCodeException::class);
5449
$this->expectExceptionMessage('invalid version number');
5550

tests/Common/VersionTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use chillerlan\QRCode\QRCodeException;
1515
use chillerlan\QRCode\Common\{EccLevel, Version};
16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718

1819
/**
@@ -26,37 +27,45 @@ protected function setUp():void{
2627
$this->version = new Version(7);
2728
}
2829

29-
public function testToString():void{
30+
#[Test]
31+
public function versionToString():void{
3032
$this::assertSame('7', (string)$this->version);
3133
}
3234

33-
public function testGetVersionNumber():void{
35+
#[Test]
36+
public function getVersionNumber():void{
3437
$this::assertSame(7, $this->version->getVersionNumber());
3538
}
3639

37-
public function testGetDimension():void{
40+
#[Test]
41+
public function getDimension():void{
3842
$this::assertSame(45, $this->version->getDimension());
3943
}
4044

41-
public function testGetVersionPattern():void{
45+
#[Test]
46+
public function getVersionPattern():void{
4247
$this::assertSame(0b000111110010010100, $this->version->getVersionPattern());
4348
// no pattern for version < 7
4449
$this::assertNull((new Version(6))->getVersionPattern());
4550
}
4651

47-
public function testGetAlignmentPattern():void{
52+
#[Test]
53+
public function getAlignmentPattern():void{
4854
$this::assertSame([6, 22, 38], $this->version->getAlignmentPattern());
4955
}
5056

51-
public function testGetRSBlocks():void{
57+
#[Test]
58+
public function getRSBlocks():void{
5259
$this::assertSame([18, [[2, 14], [4, 15]]], $this->version->getRSBlocks(new EccLevel(EccLevel::Q)));
5360
}
5461

55-
public function testGetTotalCodewords():void{
62+
#[Test]
63+
public function getTotalCodewords():void{
5664
$this::assertSame(196, $this->version->getTotalCodewords());
5765
}
5866

59-
public function testConstructInvalidVersion():void{
67+
#[Test]
68+
public function constructInvalidVersion():void{
6069
$this->expectException(QRCodeException::class);
6170
$this->expectExceptionMessage('invalid version given');
6271

tests/Data/AlphaNumTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
namespace chillerlan\QRCodeTest\Data;
1313

14-
use chillerlan\QRCode\Data\AlphaNum;
15-
use chillerlan\QRCode\Data\QRDataModeInterface;
14+
use chillerlan\QRCode\Data\{AlphaNum, QRDataModeInterface};
1615

1716
/**
1817
* Tests the AlphaNum class

0 commit comments

Comments
 (0)