ModeTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\QRCodeException;
  12. use chillerlan\QRCode\Common\Mode;
  13. use PHPUnit\Framework\Attributes\DataProvider;
  14. use PHPUnit\Framework\TestCase;
  15. /**
  16. * Mode coverage test
  17. */
  18. final class ModeTest extends TestCase{
  19. /**
  20. * version breakpoints for numeric mode
  21. *
  22. * @phpstan-return array<int, array{0: int, 1: int}>
  23. */
  24. public static function versionProvider():array{
  25. return [
  26. [ 1, 10],
  27. [ 9, 10],
  28. [10, 12],
  29. [26, 12],
  30. [27, 14],
  31. [40, 14],
  32. ];
  33. }
  34. #[DataProvider('versionProvider')]
  35. public function testGetLengthBitsForVersionBreakpoints(int $version, int $expected):void{
  36. $this::assertSame($expected, Mode::getLengthBitsForVersion(Mode::NUMBER, $version));
  37. }
  38. public function testGetLengthBitsForVersionInvalidModeException():void{
  39. $this->expectException(QRCodeException::class);
  40. $this->expectExceptionMessage('invalid mode given');
  41. Mode::getLengthBitsForVersion(42, 69);
  42. }
  43. public function testGetLengthBitsForVersionInvalidVersionException():void{
  44. $this->expectException(QRCodeException::class);
  45. $this->expectExceptionMessage('invalid version number');
  46. Mode::getLengthBitsForVersion(Mode::BYTE, 69);
  47. }
  48. }