ImageTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. *
  4. * @filesource ImageTest.php
  5. * @created 08.02.2016
  6. * @package chillerlan\QRCodeTest\Output
  7. * @author Smiley <smiley@chillerlan.net>
  8. * @copyright 2015 Smiley
  9. * @license MIT
  10. */
  11. namespace chillerlan\QRCodeTest\Output;
  12. use chillerlan\QRCode\Output\QRImage;
  13. use chillerlan\QRCode\Output\QRImageOptions;
  14. use chillerlan\QRCode\QRCode;
  15. class ImageTest extends OutputTestAbstract{
  16. protected $outputInterfaceClass = QRImage::class;
  17. protected $outputOptionsClass = QRImageOptions::class;
  18. public function testOptions(){
  19. $this->assertEquals(QRCode::OUTPUT_IMAGE_PNG, $this->options->type);
  20. $this->assertEquals(true, $this->options->base64);
  21. }
  22. public function imageDataProvider(){
  23. return [
  24. [QRCode::OUTPUT_IMAGE_PNG, 'foobar', 'img1.png.uri'],
  25. [QRCode::OUTPUT_IMAGE_GIF, 'foobar', 'img1.gif.uri'],
  26. [QRCode::OUTPUT_IMAGE_JPG, 'foobar', 'img1.jpg.uri'],
  27. [QRCode::OUTPUT_IMAGE_PNG, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.png.uri'],
  28. [QRCode::OUTPUT_IMAGE_GIF, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.gif.uri'],
  29. [QRCode::OUTPUT_IMAGE_JPG, 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', 'img2.jpg.uri'],
  30. ];
  31. }
  32. /**
  33. * @dataProvider imageDataProvider
  34. */
  35. public function testImageOutput($type, $data, $expected){
  36. $this->options->type = $type;
  37. $output = (new QRCode($data, new $this->outputInterfaceClass($this->options)))->output();
  38. // jpeg test is causing trouble
  39. if($type === QRCode::OUTPUT_IMAGE_JPG){
  40. $this->markTestSkipped('jpeg test skipped');
  41. }
  42. // skip png for PHP 7.2 https://travis-ci.org/codemasher/php-qrcode/jobs/292110988
  43. else if($type === QRCode::OUTPUT_IMAGE_PNG && PHP_VERSION_ID >= 70200){
  44. $this->markTestSkipped('png test skipped, PHP version: '.PHP_VERSION);
  45. }
  46. else{
  47. $this->assertEquals(file_get_contents(__DIR__.'/image/'.$expected), $output);
  48. }
  49. }
  50. }