ModeTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\{Test, TestWith};
  15. use PHPUnit\Framework\TestCase;
  16. /**
  17. * Mode coverage test
  18. */
  19. final class ModeTest extends TestCase{
  20. /**
  21. * Tests the version breakpoints for numeric mode
  22. */
  23. #[Test]
  24. #[TestWith([ 1, 10], '10 low')]
  25. #[TestWith([ 9, 10], '10 high')]
  26. #[TestWith([10, 12], '12 low')]
  27. #[TestWith([26, 12], '12 high')]
  28. #[TestWith([27, 14], '14 low')]
  29. #[TestWith([40, 14], '14 high')]
  30. public function getLengthBitsForVersionBreakpoints(int $version, int $expected):void{
  31. $this::assertSame($expected, Mode::getLengthBitsForVersion(Mode::NUMBER, $version));
  32. }
  33. #[Test]
  34. public function getLengthBitsForVersionInvalidModeException():void{
  35. $this->expectException(QRCodeException::class);
  36. $this->expectExceptionMessage('invalid mode given');
  37. Mode::getLengthBitsForVersion(42, 69);
  38. }
  39. #[Test]
  40. public function getLengthBitsForVersionInvalidVersionException():void{
  41. $this->expectException(QRCodeException::class);
  42. $this->expectExceptionMessage('invalid version number');
  43. Mode::getLengthBitsForVersion(Mode::BYTE, 69);
  44. }
  45. }