ECICharsetTest.php 1.2 KB

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