BitArrayTest.php
8 months ago
BitMatrixTest.php
8 months ago
BitUtilsTest.php
8 months ago
ErrorCorrectionLevelTest.php
8 months ago
FormatInformationTest.php
8 months ago
ModeTest.php
8 months ago
ReedSolomonCodecTest.php
8 months ago
VersionTest.php
8 months ago
VersionTest.php
79 lines
| 1 | <?php |
| 2 | declare(strict_types = 1); |
| 3 | |
| 4 | namespace BaconQrCodeTest\Common; |
| 5 | |
| 6 | use BaconQrCode\Common\ErrorCorrectionLevel; |
| 7 | use BaconQrCode\Common\Version; |
| 8 | use PHPUnit\Framework\TestCase; |
| 9 | |
| 10 | class VersionTest extends TestCase |
| 11 | { |
| 12 | public function versions() : array |
| 13 | { |
| 14 | $array = []; |
| 15 | |
| 16 | for ($i = 1; $i <= 40; ++$i) { |
| 17 | $array[] = [$i, 4 * $i + 17]; |
| 18 | } |
| 19 | |
| 20 | return $array; |
| 21 | } |
| 22 | |
| 23 | public function decodeInformation() : array |
| 24 | { |
| 25 | return [ |
| 26 | [7, 0x07c94], |
| 27 | [12, 0x0c762], |
| 28 | [17, 0x1145d], |
| 29 | [22, 0x168c9], |
| 30 | [27, 0x1b08e], |
| 31 | [32, 0x209d5], |
| 32 | ]; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @dataProvider versions |
| 37 | */ |
| 38 | public function testVersionForNumber(int $versionNumber, int $dimension) : void |
| 39 | { |
| 40 | $version = Version::getVersionForNumber($versionNumber); |
| 41 | |
| 42 | $this->assertNotNull($version); |
| 43 | $this->assertEquals($versionNumber, $version->getVersionNumber()); |
| 44 | $this->assertNotNull($version->getAlignmentPatternCenters()); |
| 45 | |
| 46 | if ($versionNumber > 1) { |
| 47 | $this->assertTrue(count($version->getAlignmentPatternCenters()) > 0); |
| 48 | } |
| 49 | |
| 50 | $this->assertEquals($dimension, $version->getDimensionForVersion()); |
| 51 | $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::H())); |
| 52 | $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::L())); |
| 53 | $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::M())); |
| 54 | $this->assertNotNull($version->getEcBlocksForLevel(ErrorCorrectionLevel::Q())); |
| 55 | $this->assertNotNull($version->buildFunctionPattern()); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @dataProvider versions |
| 60 | */ |
| 61 | public function testGetProvisionalVersionForDimension(int $versionNumber, int $dimension) : void |
| 62 | { |
| 63 | $this->assertSame( |
| 64 | $versionNumber, |
| 65 | Version::getProvisionalVersionForDimension($dimension)->getVersionNumber() |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @dataProvider decodeInformation |
| 71 | */ |
| 72 | public function testDecodeVersionInformation(int $expectedVersion, int $mask) : void |
| 73 | { |
| 74 | $version = Version::decodeVersionInformation($mask); |
| 75 | $this->assertNotNull($version); |
| 76 | $this->assertSame($expectedVersion, $version->getVersionNumber()); |
| 77 | } |
| 78 | } |
| 79 |