Skip to content

Commit

Permalink
Use validation reader to check exact text
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Feb 13, 2018
1 parent 927dd3a commit 03fb630
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/QrCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Endroid\QrCode\Factory\QrCodeFactory;
use Endroid\QrCode\QrCode;
use PHPUnit\Framework\TestCase;
use QrReader;

class QrCodeTest extends TestCase
{
Expand All @@ -28,12 +29,14 @@ public function testReadable(): void
'有限公司',
];

$qrCode = new QrCode();
$qrCode->setSize(300);
foreach ($messages as $message) {
$qrCode = new QrCode($message);
$qrCode->setSize(300);
$qrCode->setValidateResult(true);
$qrCode->setText($message);
$pngData = $qrCode->writeString();
$this->assertTrue(is_string($pngData));
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
$this->assertEquals($message, $reader->text());
}
}

Expand All @@ -48,11 +51,13 @@ public function testFactory(): void

$pngData = $qrCode->writeString();
$this->assertTrue(is_string($pngData));
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
$this->assertEquals('QR Code', $reader->text());
}

public function testWriteQrCode(): void
{
$qrCode = new QrCode('QrCode');
$qrCode = new QrCode('QR Code');

$qrCode->setWriterByName('binary');
$binData = $qrCode->writeString();
Expand Down Expand Up @@ -84,7 +89,7 @@ public function testSetSize(): void
$size = 400;
$margin = 10;

$qrCode = new QrCode('QrCode');
$qrCode = new QrCode('QR Code');
$qrCode->setSize($size);
$qrCode->setMargin($margin);

Expand All @@ -97,20 +102,22 @@ public function testSetSize(): void

public function testSetLabel(): void
{
$qrCode = new QrCode('QrCode');
$qrCode = new QrCode('QR Code');
$qrCode->setSize(300);
$qrCode->setLabel('Scan the code', 15);

$pngData = $qrCode->writeString();
$this->assertTrue(is_string($pngData));
$reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB);
$this->assertEquals('QR Code', $reader->text());
}

public function testSetLogo(): void
{
$qrCode = new QrCode('QrCode');
$qrCode->setSize(400);
$qrCode = new QrCode('QR Code');
$qrCode->setSize(500);
$qrCode->setLogoPath(__DIR__.'/../assets/images/symfony.png');
$qrCode->setLogoWidth(150);
$qrCode->setLogoWidth(100);
$qrCode->setValidateResult(true);

$pngData = $qrCode->writeString();
Expand All @@ -121,7 +128,7 @@ public function testWriteFile(): void
{
$filename = __DIR__.'/output/qr-code.png';

$qrCode = new QrCode('QrCode');
$qrCode = new QrCode('QR Code');
$qrCode->writeFile($filename);

$image = imagecreatefromstring(file_get_contents($filename));
Expand Down

0 comments on commit 03fb630

Please sign in to comment.