QRDataTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Class QRDataTest
  4. *
  5. * @created 08.08.2022
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2022 smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Data;
  11. use chillerlan\QRCode\Common\BitBuffer;
  12. use chillerlan\QRCode\Common\MaskPattern;
  13. use chillerlan\QRCode\Data\QRData;
  14. use chillerlan\QRCode\Output\QRGdImagePNG;
  15. use chillerlan\QRCode\QRCode;
  16. use chillerlan\QRCode\QROptions;
  17. use chillerlan\QRCodeTest\QRMatrixDebugTrait;
  18. use PHPUnit\Framework\TestCase;
  19. /**
  20. *
  21. */
  22. final class QRDataTest extends TestCase{
  23. use QRMatrixDebugTrait;
  24. /**
  25. * tests setting the BitBuffer object directly
  26. */
  27. public function testSetBitBuffer():void{
  28. $rawBytes = [
  29. 67, 22, 135, 71, 71, 7, 51, 162, 242, 247, 119, 119, 114, 231, 150, 247,
  30. 87, 71, 86, 38, 82, 230, 54, 246, 210, 247, 118, 23, 70, 54, 131, 247,
  31. 99, 212, 68, 199, 167, 135, 39, 164, 100, 55, 148, 247, 50, 103, 67, 211,
  32. 67, 55, 48, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  33. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  34. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  35. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  36. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  37. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  38. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  39. ];
  40. $options = new QROptions(['version' => 3]);
  41. $bitBuffer = new BitBuffer($rawBytes);
  42. $matrix = (new QRData($options))->setBitBuffer($bitBuffer)->writeMatrix();
  43. $maskPattern = MaskPattern::getBestPattern($matrix);
  44. $matrix->setFormatInfo($maskPattern)->mask($maskPattern);
  45. $this::assertSame(3, $matrix->getVersion()->getVersionNumber());
  46. // attempt to read
  47. $options->outputBase64 = false;
  48. $options->readerUseImagickIfAvailable = false;
  49. $output = new QRGdImagePNG($options, $matrix);
  50. $decodeResult = (new QRCode($options))->readFromBlob($output->dump());
  51. $this->debugMatrix($matrix);
  52. $this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s');
  53. }
  54. }