ModeTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. public static function versionProvider():array{
  23. return [
  24. [ 1, 10],
  25. [ 9, 10],
  26. [10, 12],
  27. [26, 12],
  28. [27, 14],
  29. [40, 14],
  30. ];
  31. }
  32. #[DataProvider('versionProvider')]
  33. public function testGetLengthBitsForVersionBreakpoints(int $version, int $expected):void{
  34. $this::assertSame($expected, Mode::getLengthBitsForVersion(Mode::NUMBER, $version));
  35. }
  36. public function testGetLengthBitsForVersionInvalidModeException():void{
  37. $this->expectException(QRCodeException::class);
  38. $this->expectExceptionMessage('invalid mode given');
  39. /** @phan-suppress-next-line PhanNoopNew */
  40. Mode::getLengthBitsForVersion(42, 69);
  41. }
  42. public function testGetLengthBitsForVersionInvalidVersionException():void{
  43. $this->expectException(QRCodeException::class);
  44. $this->expectExceptionMessage('invalid version number');
  45. /** @phan-suppress-next-line PhanNoopNew */
  46. Mode::getLengthBitsForVersion(Mode::BYTE, 69);
  47. }
  48. }