ModeTest.php 1.4 KB

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