ModeTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Class ModeTest
  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\Mode;
  12. use chillerlan\QRCode\QRCodeException;
  13. use PHPUnit\Framework\TestCase;
  14. /**
  15. * Mode coverage test
  16. */
  17. final class ModeTest extends TestCase{
  18. /**
  19. * version breakpoints for numeric mode
  20. */
  21. public static function versionProvider():array{
  22. return [
  23. [ 1, 10],
  24. [ 9, 10],
  25. [10, 12],
  26. [26, 12],
  27. [27, 14],
  28. [40, 14],
  29. ];
  30. }
  31. /**
  32. * @dataProvider versionProvider
  33. */
  34. public function testGetLengthBitsForVersionBreakpoints(int $version, int $expected):void{
  35. $this::assertSame($expected, Mode::getLengthBitsForVersion(Mode::NUMBER, $version));
  36. }
  37. public function testGetLengthBitsForVersionInvalidModeException():void{
  38. $this->expectException(QRCodeException::class);
  39. $this->expectExceptionMessage('invalid mode given');
  40. /** @phan-suppress-next-line PhanNoopNew */
  41. Mode::getLengthBitsForVersion(42, 69);
  42. }
  43. public function testGetLengthBitsForVersionInvalidVersionException():void{
  44. $this->expectException(QRCodeException::class);
  45. $this->expectExceptionMessage('invalid version number');
  46. /** @phan-suppress-next-line PhanNoopNew */
  47. Mode::getLengthBitsForVersion(Mode::BYTE, 69);
  48. }
  49. public function testGetLengthBitsForModeInvalidModeException():void{
  50. $this->expectException(QRCodeException::class);
  51. $this->expectExceptionMessage('invalid mode given');
  52. /** @phan-suppress-next-line PhanNoopNew */
  53. Mode::getLengthBitsForMode(42);
  54. }
  55. }