QRImageTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Class QRImageTest
  4. *
  5. * @filesource QRImageTest.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, Output\QRImage};
  14. use const PHP_MAJOR_VERSION;
  15. class QRImageTest extends QROutputTestAbstract{
  16. protected $FQCN = QRImage::class;
  17. public function types(){
  18. return [
  19. 'png' => [QRCode::OUTPUT_IMAGE_PNG],
  20. 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
  21. 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
  22. ];
  23. }
  24. /**
  25. * @dataProvider types
  26. * @param $type
  27. */
  28. public function testImageOutput($type){
  29. $this->options->outputType = $type;
  30. $this->options->imageBase64 = false;
  31. $this->setOutputInterface();
  32. $this->outputInterface->dump($this::cachefile.$type);
  33. $img = $this->outputInterface->dump();
  34. if($type === QRCode::OUTPUT_IMAGE_JPG){ // jpeg encoding may cause different results
  35. $this->markAsRisky();
  36. }
  37. $this->assertSame($img, file_get_contents($this::cachefile.$type));
  38. }
  39. public function testSetModuleValues(){
  40. $this->options->moduleValues = [
  41. // data
  42. 1024 => [0, 0, 0],
  43. 4 => [255, 255, 255],
  44. ];
  45. $this->setOutputInterface()->dump();
  46. $this->assertTrue(true); // tricking the code coverage
  47. }
  48. public function testOutputGetResource():void{
  49. $this->options->returnResource = true;
  50. $this->setOutputInterface();
  51. $data = $this->outputInterface->dump();
  52. if(PHP_MAJOR_VERSION >= 8){
  53. $this::assertInstanceOf('\\GdImage', $data);
  54. }
  55. else{
  56. $this::assertIsResource($data);
  57. }
  58. }
  59. }