ECICharsetTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. public static function invalidIdProvider():array{
  17. return [[-1], [1000000]];
  18. }
  19. #[DataProvider('invalidIdProvider')]
  20. public function testInvalidDataException(int $id):void{
  21. $this->expectException(QRCodeException::class);
  22. $this->expectExceptionMessage('invalid charset id:');
  23. /** @phan-suppress-next-line PhanNoopNew */
  24. new ECICharset($id);
  25. }
  26. public static function encodingProvider():array{
  27. $params = [];
  28. foreach(ECICharset::MB_ENCODINGS as $id => $name){
  29. $params[] = [$id, $name];
  30. }
  31. return $params;
  32. }
  33. #[DataProvider('encodingProvider')]
  34. public function testGetName(int $id, string $name = null):void{
  35. $eciCharset = new ECICharset($id);
  36. $this::assertSame($id, $eciCharset->getID());
  37. $this::assertSame($name, $eciCharset->getName());
  38. }
  39. }