VersionTest.php 1.6 KB

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