ImageTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. use SimpleSoftwareIO\QrCode\Image;
  3. class ImageTest extends \PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * The location to save the testing image.
  7. *
  8. * @var string
  9. */
  10. protected $testImageSaveLocation;
  11. /**
  12. * The location to save the compare image.
  13. *
  14. * @var string
  15. */
  16. protected $compareTestSaveLocation;
  17. /**
  18. * The path to the image used to test.
  19. *
  20. * @var string
  21. */
  22. protected $imagePath;
  23. /**
  24. * The Image object.
  25. *
  26. * @var Image
  27. */
  28. protected $image;
  29. public function setUp()
  30. {
  31. $this->imagePath = file_get_contents(dirname(__FILE__).'/Images/simplesoftware-icon-grey-blue.png');
  32. $this->image = new Image($this->imagePath);
  33. $this->testImageSaveLocation = dirname(__FILE__).'/testImage.png';
  34. $this->compareTestSaveLocation = dirname(__FILE__).'/compareImage.png';
  35. }
  36. public function tearDown()
  37. {
  38. @unlink($this->testImageSaveLocation);
  39. @unlink($this->compareTestSaveLocation);
  40. }
  41. /**
  42. * Must test that the outputted PNG is the same because you can not compare resources.
  43. */
  44. public function test_it_loads_an_image_string_into_a_resource()
  45. {
  46. imagepng(imagecreatefromstring($this->imagePath), $this->compareTestSaveLocation);
  47. imagepng($this->image->getImageResource(), $this->testImageSaveLocation);
  48. $correctImage = file_get_contents($this->compareTestSaveLocation);
  49. $testImage = file_get_contents($this->testImageSaveLocation);
  50. $this->assertEquals($correctImage, $testImage);
  51. }
  52. public function test_it_gets_the_correct_height()
  53. {
  54. $correctHeight = 512;
  55. $testHeight = $this->image->getHeight();
  56. $this->assertEquals($correctHeight, $testHeight);
  57. }
  58. public function test_it_gets_the_correct_width()
  59. {
  60. $correctWidth = 512;
  61. $testWidth = $this->image->getWidth();
  62. $this->assertEquals($correctWidth, $testWidth);
  63. }
  64. }