annotate vendor/endroid/qr-code/tests/QrCodeTest.php @ 6:cec75ba50afc

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