|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Class VersionTest |
| 4 | + * |
| 5 | + * @created 25.07.2022 |
| 6 | + * @author smiley <[email protected]> |
| 7 | + * @copyright 2022 smiley |
| 8 | + * @license MIT |
| 9 | + */ |
| 10 | + |
| 11 | +namespace chillerlan\QRCodeTest\Common; |
| 12 | + |
| 13 | +use chillerlan\QRCode\Common\EccLevel; |
| 14 | +use chillerlan\QRCode\Common\Mode; |
| 15 | +use chillerlan\QRCode\Common\Version; |
| 16 | +use chillerlan\QRCode\QRCodeException; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * Version coverage test |
| 21 | + */ |
| 22 | +final class VersionTest extends TestCase{ |
| 23 | + |
| 24 | + private Version $version; |
| 25 | + |
| 26 | + protected function setUp():void{ |
| 27 | + $this->version = new Version(7); |
| 28 | + } |
| 29 | + |
| 30 | + public function testToString():void{ |
| 31 | + $this::assertSame('7', (string)$this->version); |
| 32 | + } |
| 33 | + |
| 34 | + public function testGetVersionNumber():void{ |
| 35 | + $this::assertSame(7, $this->version->getVersionNumber()); |
| 36 | + } |
| 37 | + |
| 38 | + public function testGetDimension():void{ |
| 39 | + $this::assertSame(45, $this->version->getDimension()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testGetVersionPattern():void{ |
| 43 | + $this::assertSame(0b000111110010010100, $this->version->getVersionPattern()); |
| 44 | + // no pattern for version < 7 |
| 45 | + $this::assertNull((new Version(6))->getVersionPattern()); |
| 46 | + } |
| 47 | + |
| 48 | + public function testGetAlignmentPattern():void{ |
| 49 | + $this::assertSame([6, 22, 38], $this->version->getAlignmentPattern()); |
| 50 | + } |
| 51 | + |
| 52 | + public function testGetRSBlocks():void{ |
| 53 | + $this::assertSame([18, [[2, 14], [4, 15]]], $this->version->getRSBlocks(new EccLevel(EccLevel::Q))); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetTotalCodewords():void{ |
| 57 | + $this::assertSame(196, $this->version->getTotalCodewords()); |
| 58 | + } |
| 59 | + |
| 60 | + public function testConstructInvalidVersion():void{ |
| 61 | + $this->expectException(QRCodeException::class); |
| 62 | + $this->expectExceptionMessage('invalid version given'); |
| 63 | + |
| 64 | + $version = new Version(69); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments