QRDataTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\QRGdImage;
  15. use chillerlan\QRCode\QRCode;
  16. use chillerlan\QRCode\QROptions;
  17. use PHPUnit\Framework\TestCase;
  18. /**
  19. *
  20. */
  21. final class QRDataTest extends TestCase{
  22. /**
  23. * tests setting the BitBuffer object directly
  24. */
  25. public function testSetBitBuffer():void{
  26. $rawBytes = [
  27. 67, 22, 135, 71, 71, 7, 51, 162, 242, 247, 119, 119, 114, 231, 150, 247,
  28. 87, 71, 86, 38, 82, 230, 54, 246, 210, 247, 118, 23, 70, 54, 131, 247,
  29. 99, 212, 68, 199, 167, 135, 39, 164, 100, 55, 148, 247, 50, 103, 67, 211,
  30. 67, 55, 48, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  31. 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236,
  32. 17, 236, 17, 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,
  37. ];
  38. $options = new QROptions(['version' => 3]);
  39. $bitBuffer = new BitBuffer($rawBytes);
  40. $QRData = (new QRData($options))->setBitBuffer($bitBuffer);
  41. $maskPattern = MaskPattern::getBestPattern($QRData);
  42. $matrix = $QRData->writeMatrix($maskPattern);
  43. $this::assertSame(3, $matrix->getVersion()->getVersionNumber());
  44. // attempt to read
  45. $options->imageBase64 = false;
  46. $options->readerUseImagickIfAvailable = false;
  47. $output = new QRGdImage($options, $matrix);
  48. $decodeResult = (new QRCode($options))->readFromBlob($output->dump());
  49. QRMatrixTest::debugMatrix($matrix);
  50. $this::assertSame($decodeResult->data, 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s');
  51. }
  52. }