QRStringTest.php 1.8 KB

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