ECICharsetTest.php 1.3 KB

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