EccLevelTest.php 1.2 KB

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