Skip to content

Commit ebdb6d5

Browse files
author
Martin Brecht-Precht
committed
Added QrCodeRenderer tests.
1 parent dccfb0b commit ebdb6d5

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace QrCodeSuite\QrRender;
4+
5+
use QrCodeSuite\QrEncode\QrEncoder;
6+
7+
/**
8+
* Class QrCodeRendererEpsTest
9+
*
10+
* @package QrCodeSuite\QrRender
11+
*/
12+
class QrCodeRendererEpsTest extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
const QR_CODE_CONTENT = 'Commodo Adipiscing Justo Vehicula Tellus';
16+
17+
public function testRender()
18+
{
19+
// Encode content
20+
$qrEncoder = new QrEncoder();
21+
$qrCode = $qrEncoder
22+
->setLevel(QrEncoder::QR_CODE_LEVEL_LOW)
23+
->setTempDir(__DIR__ . '/tmp/')
24+
->encodeQrCode(self::QR_CODE_CONTENT);
25+
26+
// Render image
27+
$qrCodeOutputPath = __DIR__ . '/tmp/qrcode-test.eps';
28+
$qrCodeRendererPng = new QrCodeRendererEps();
29+
$qrCodeRendererPng->render($qrCode, $qrCodeOutputPath);
30+
31+
// Test QR code output file exists
32+
$this->assertFileExists($qrCodeOutputPath);
33+
34+
// Remove test QR code output file
35+
unlink($qrCodeOutputPath);
36+
}
37+
38+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace QrCodeSuite\QrRender;
4+
5+
use QrCodeSuite\QrEncode\QrEncoder;
6+
7+
/**
8+
* Class QrCodeRendererPngTest
9+
*
10+
* @package QrCodeSuite\QrRender
11+
*/
12+
class QrCodeRendererPngTest extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
const QR_CODE_CONTENT = 'Commodo Adipiscing Justo Vehicula Tellus';
16+
17+
public function testRender()
18+
{
19+
// Encode content
20+
$qrEncoder = new QrEncoder();
21+
$qrCode = $qrEncoder
22+
->setLevel(QrEncoder::QR_CODE_LEVEL_LOW)
23+
->setTempDir(__DIR__ . '/tmp/')
24+
->encodeQrCode(self::QR_CODE_CONTENT);
25+
26+
// Render image
27+
$qrCodeOutputPath = __DIR__ . '/tmp/qrcode-test.png';
28+
$qrCodeRendererPng = new QrCodeRendererPng();
29+
$qrCodeRendererPng->render($qrCode, $qrCodeOutputPath);
30+
31+
// Test QR code output file exists
32+
$this->assertFileExists($qrCodeOutputPath);
33+
34+
// Test QR code output file mesaurement
35+
$blockSize = ceil(1000 / ($qrCode->getWidth() + 2 * QrCodeRendererPng::MARGIN));
36+
$symbolWidth = ($qrCode->getWidth() + 2 * QrCodeRendererPng::MARGIN) * $blockSize;
37+
$symbolHeight = ($qrCode->getHeight() + 2 * QrCodeRendererPng::MARGIN) * $blockSize;
38+
$imageSize = getimagesize($qrCodeOutputPath);
39+
$this->assertEquals($symbolWidth, $imageSize[0]);
40+
$this->assertEquals($symbolHeight, $imageSize[1]);
41+
42+
// Remove test QR code output file
43+
unlink($qrCodeOutputPath);
44+
}
45+
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace QrCodeSuite\QrRender;
4+
5+
use QrCodeSuite\QrEncode\QrEncoder;
6+
7+
/**
8+
* Class QrCodeRendererTiffTest
9+
*
10+
* @package QrCodeSuite\QrRender
11+
*/
12+
class QrCodeRendererTiffTest extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
const QR_CODE_CONTENT = 'Commodo Adipiscing Justo Vehicula Tellus';
16+
17+
public function testRender()
18+
{
19+
// Encode content
20+
$qrEncoder = new QrEncoder();
21+
$qrCode = $qrEncoder
22+
->setLevel(QrEncoder::QR_CODE_LEVEL_LOW)
23+
->setTempDir(__DIR__ . '/tmp/')
24+
->encodeQrCode(self::QR_CODE_CONTENT);
25+
26+
// Render image
27+
$qrCodeOutputPath = __DIR__ . '/tmp/qrcode-test.tif';
28+
$qrCodeRendererPng = new QrCodeRendererTiff();
29+
$qrCodeRendererPng->render($qrCode, $qrCodeOutputPath);
30+
31+
// Test QR code output file exists
32+
$this->assertFileExists($qrCodeOutputPath);
33+
34+
// Test QR code output file mesaurement
35+
$blockSize = ceil(1000 / ($qrCode->getWidth() + 2 * QrCodeRendererPng::MARGIN));
36+
$symbolWidth = ($qrCode->getWidth() + 2 * QrCodeRendererPng::MARGIN) * $blockSize;
37+
$symbolHeight = ($qrCode->getHeight() + 2 * QrCodeRendererPng::MARGIN) * $blockSize;
38+
$imageSize = getimagesize($qrCodeOutputPath);
39+
$this->assertEquals($symbolWidth, $imageSize[0]);
40+
$this->assertEquals($symbolHeight, $imageSize[1]);
41+
42+
// Remove test QR code output file
43+
unlink($qrCodeOutputPath);
44+
}
45+
46+
}

test/QrRender/tmp/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

0 commit comments

Comments
 (0)