VersionTest.php 1.6 KB

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