ECICharsetTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * ECICharsetTest.php
  4. *
  5. * @created 13.03.2023
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2023 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\ECICharset;
  14. use PHPUnit\Framework\Attributes\DataProvider;
  15. use PHPUnit\Framework\TestCase;
  16. final class ECICharsetTest extends TestCase{
  17. /**
  18. * @phpstan-return array<int, array{0: int}>
  19. */
  20. public static function invalidIdProvider():array{
  21. return [[-1], [1000000]];
  22. }
  23. #[DataProvider('invalidIdProvider')]
  24. public function testInvalidDataException(int $id):void{
  25. $this->expectException(QRCodeException::class);
  26. $this->expectExceptionMessage('invalid charset id:');
  27. new ECICharset($id);
  28. }
  29. /**
  30. * @phpstan-return array<int, array{0: int, 1: (string|null)}>
  31. */
  32. public static function encodingProvider():array{
  33. $params = [];
  34. foreach(ECICharset::MB_ENCODINGS as $id => $name){
  35. $params[] = [$id, $name];
  36. }
  37. return $params;
  38. }
  39. #[DataProvider('encodingProvider')]
  40. public function testGetName(int $id, string|null $name = null):void{
  41. $eciCharset = new ECICharset($id);
  42. $this::assertSame($id, $eciCharset->getID());
  43. $this::assertSame($name, $eciCharset->getName());
  44. }
  45. }