QRGdImageTestAbstract.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /**
  16. * Tests the QRGdImage output module
  17. */
  18. abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
  19. /**
  20. * @inheritDoc
  21. */
  22. protected function setUp():void{
  23. if(!extension_loaded('gd')){
  24. $this::markTestSkipped('ext-gd not loaded');
  25. }
  26. parent::setUp();
  27. }
  28. public static function moduleValueProvider():array{
  29. return [
  30. 'valid: int' => [[123, 123, 123], true],
  31. 'valid: w/invalid extra element' => [[123, 123, 123, 'abc'], true],
  32. 'valid: numeric string' => [['123', '123', '123'], true],
  33. 'invalid: wrong type' => ['foo', false],
  34. 'invalid: array too short' => [[1, 2], false],
  35. 'invalid: contains non-number' => [[1, 'b', 3], false],
  36. ];
  37. }
  38. /**
  39. * @inheritDoc
  40. */
  41. public function testSetModuleValues():void{
  42. $this->options->moduleValues = [
  43. // data
  44. QRMatrix::M_DATA_DARK => [0, 0, 0],
  45. QRMatrix::M_DATA => [255, 255, 255],
  46. ];
  47. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  48. $this->outputInterface->dump();
  49. $this::assertTrue(true); // tricking the code coverage
  50. }
  51. public function testOutputGetResource():void{
  52. $this->options->returnResource = true;
  53. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  54. $this::assertInstanceOf(GdImage::class, $this->outputInterface->dump());
  55. }
  56. public function testBase64MimeType():void{
  57. $this->options->outputBase64 = true;
  58. $this->outputInterface = new $this->FQN($this->options, $this->matrix);
  59. $this::assertStringContainsString($this->outputInterface::MIME_TYPE, $this->outputInterface->dump());
  60. }
  61. }