QRGdImageTestAbstract.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Class QRGdImageTestAbstract
  4. *
  5. * @created 24.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. *
  10. * @noinspection PhpComposerExtensionStubsInspection
  11. */
  12. namespace chillerlan\QRCodeTest\Output;
  13. use chillerlan\QRCode\Data\QRMatrix;
  14. use GdImage;
  15. use function extension_loaded;
  16. /**
  17. * Tests the QRGdImage output module
  18. */
  19. abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
  20. /**
  21. * @inheritDoc
  22. */
  23. protected function setUp():void{
  24. if(!extension_loaded('gd')){
  25. $this::markTestSkipped('ext-gd not loaded');
  26. }
  27. parent::setUp();
  28. }
  29. public static function moduleValueProvider():array{
  30. return [
  31. 'valid: int' => [[123, 123, 123], true],
  32. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  33. 'valid: numeric string' => [['123', '123', '123'], true],
  34. 'invalid: wrong type' => ['foo', false],
  35. 'invalid: array too short' => [[1, 2], false],
  36. 'invalid: contains non-number' => [[1, 'b', 3], false],
  37. ];
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. public function testSetModuleValues():void{
  43. $this->options->moduleValues = [
  44. // data
  45. QRMatrix::M_DATA_DARK => [0, 0, 0],
  46. QRMatrix::M_DATA => [255, 255, 255],
  47. ];
  48. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  49. $this->outputInterface->dump();
  50. $this::assertTrue(true); // tricking the code coverage
  51. }
  52. public function testOutputGetResource():void{
  53. $this->options->returnResource = true;
  54. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  55. $this::assertInstanceOf(GdImage::class, $this->outputInterface->dump());
  56. }
  57. public function testBase64MimeType():void{
  58. $this->options->outputBase64 = true;
  59. $this->outputInterface = $this->getOutputInterface($this->options, $this->matrix);
  60. $this::assertStringContainsString($this->outputInterface::MIME_TYPE, $this->outputInterface->dump());
  61. }
  62. }