VersionTest.php 1.6 KB

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