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