Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

QrCodeTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /*
  3. * (c) Jeroen van den Enden <info@endroid.nl>
  4. *
  5. * This source file is subject to the MIT license that is bundled
  6. * with this source code in the file LICENSE.
  7. */
  8. namespace Endroid\Tests\QrCode;
  9. use Endroid\QrCode\Exceptions\ImageFunctionFailedException;
  10. use Endroid\QrCode\Exceptions\ImageFunctionUnknownException;
  11. use Endroid\QrCode\QrCode;
  12. use PHPUnit_Framework_TestCase;
  13. class QrCodeTest extends PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @var QrCode
  17. */
  18. protected $qrCode;
  19. /**
  20. * Tests if a valid data uri is returned.
  21. */
  22. public function testGetDataUri()
  23. {
  24. $qrCode = $this->getQrCode();
  25. $dataUri = $qrCode->getDataUri();
  26. $this->assertTrue(is_string($dataUri));
  27. }
  28. /**
  29. * Tests if a valid image string is returned.
  30. *
  31. * @throws ImageFunctionFailedException
  32. * @throws ImageFunctionUnknownException
  33. */
  34. public function testGetImageString()
  35. {
  36. $qrCode = $this->getQrCode();
  37. $imageString = $qrCode->get('png');
  38. $this->assertTrue(is_string($imageString));
  39. }
  40. /**
  41. * Tests if a valid image string is returned.
  42. *
  43. * @throws ImageFunctionFailedException
  44. * @throws ImageFunctionUnknownException
  45. */
  46. public function testGetQrCodeWithLogoString()
  47. {
  48. $qrCode = $this->createQrCodeWithLogo();
  49. $imageString = $qrCode->get('png');
  50. $this->assertTrue(is_string($imageString));
  51. }
  52. /**
  53. * Returns a QR code.
  54. */
  55. protected function getQrCode()
  56. {
  57. if (!$this->qrCode) {
  58. $this->qrCode = $this->createQrCode();
  59. }
  60. return $this->qrCode;
  61. }
  62. /**
  63. * Creates a QR code.
  64. *
  65. * @return QrCode
  66. */
  67. protected function createQrCode()
  68. {
  69. $qrCode = new QrCode();
  70. $qrCode->setText('Life is too short to be generating QR codes');
  71. $qrCode->setSize(300);
  72. return $qrCode;
  73. }
  74. protected function createQrCodeWithLogo()
  75. {
  76. $qrCode = new QrCode();
  77. $qrCode->setText('Life is too short to be generating QR codes')
  78. ->setSize(300)
  79. ->setLogo(dirname(__DIR__).'/assets/image/logo.png')
  80. ->setLogoSize(60);
  81. return $qrCode;
  82. }
  83. }