QRStringTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Class QRStringTest
  4. *
  5. * @created 24.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeTest\Output;
  11. use chillerlan\QRCode\{QRCode, QROptions};
  12. use chillerlan\QRCode\Common\EccLevel;
  13. use chillerlan\QRCode\Data\QRMatrix;
  14. use chillerlan\QRCode\Output\{QROutputInterface, QRString};
  15. use chillerlan\QRCodeExamples\MyCustomOutput;
  16. /**
  17. * Tests the QRString output module
  18. */
  19. final class QRStringTest extends QROutputTestAbstract{
  20. /**
  21. * @inheritDoc
  22. */
  23. protected function getOutputInterface(QROptions $options):QROutputInterface{
  24. return new QRString($options, $this->matrix);
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. public function types():array{
  30. return [
  31. 'json' => [QRCode::OUTPUT_STRING_JSON],
  32. 'text' => [QRCode::OUTPUT_STRING_TEXT],
  33. ];
  34. }
  35. /**
  36. * @inheritDoc
  37. */
  38. public function testSetModuleValues():void{
  39. $this->options->moduleValues = [
  40. // data
  41. QRMatrix::M_DATA | QRMatrix::IS_DARK => 'A',
  42. QRMatrix::M_DATA => 'B',
  43. ];
  44. $this->outputInterface = $this->getOutputInterface($this->options);
  45. $data = $this->outputInterface->dump();
  46. $this::assertStringContainsString('A', $data);
  47. $this::assertStringContainsString('B', $data);
  48. }
  49. /**
  50. * covers the custom output functionality via an example
  51. */
  52. public function testCustomOutput():void{
  53. $this->options->version = 5;
  54. $this->options->eccLevel = EccLevel::L;
  55. $this->options->outputType = QRCode::OUTPUT_CUSTOM;
  56. $this->options->outputInterface = MyCustomOutput::class;
  57. $this::assertSame(
  58. file_get_contents(__DIR__.'/../samples/custom'),
  59. (new QRCode($this->options))->render('test')
  60. );
  61. }
  62. }