EccLevelTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Class EccLevelTest
  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, MaskPattern};
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * EccLevel coverage test
  17. */
  18. final class EccLevelTest extends TestCase{
  19. public function testConstructInvalidEccException():void{
  20. $this->expectException(QRCodeException::class);
  21. $this->expectExceptionMessage('invalid ECC level');
  22. new EccLevel(69);
  23. }
  24. public function testToString():void{
  25. $ecc = new EccLevel(EccLevel::L);
  26. $this::assertSame('L', (string)$ecc);
  27. }
  28. public function testGetLevel():void{
  29. $ecc = new EccLevel(EccLevel::L);
  30. $this::assertSame(EccLevel::L, $ecc->getLevel());
  31. }
  32. public function testGetOrdinal():void{
  33. $ecc = new EccLevel(EccLevel::L);
  34. $this::assertSame(0, $ecc->getOrdinal());
  35. }
  36. public function testGetformatPattern():void{
  37. $ecc = new EccLevel(EccLevel::Q);
  38. $this::assertSame(0b010010010110100, $ecc->getformatPattern(new MaskPattern(4)));
  39. }
  40. public function getMaxBits():void{
  41. $ecc = new EccLevel(EccLevel::Q);
  42. $this::assertSame(4096, $ecc->getMaxBits()[21]);
  43. }
  44. }