diff --git a/composer.json b/composer.json index 794bb5f..78755ba 100644 --- a/composer.json +++ b/composer.json @@ -15,20 +15,21 @@ } ], "require": { - "php": "^8.0", - "endroid/qr-code": "^3.2", + "php": "^8.1", + "endroid/qr-code": "^5.0", "ext-gd": "*" }, "require-dev": { "reyesoft/ci": "2.0.1", "phpunit/phpunit": "^9.1.5", + "zxing/qr-reader": "1.2", "codedungeon/phpunit-result-printer": "0.30.0" }, "autoload": { - "classmap": [ + "classmap": [ "src/" - ], - "psr-4": { + ], + "psr-4": { "CryptoQr\\": "src/" } }, diff --git a/src/CryptoQr.php b/src/CryptoQr.php index 1218706..c7d9ce5 100644 --- a/src/CryptoQr.php +++ b/src/CryptoQr.php @@ -10,6 +10,8 @@ namespace CryptoQr; +use Endroid\QrCode\QrCode; + class CryptoQr extends Qr { /** @@ -26,6 +28,10 @@ class CryptoQr extends Qr * @var string */ protected $message = ''; + /** + * @var QrCode + */ + protected $qr_code; /** * @codeCoverageIgnore @@ -61,9 +67,7 @@ protected function updateText(): void $this->getParam('label', $this->getLabel()) . $this->getParam('message', $this->getMessage()); - $this->getQrCode()->setText( - $uri . ($params !== '' ? '?' . substr($params, 1) : '') - ); + $this->qr_code = new QrCode($uri . ($params !== '' ? '?' . substr($params, 1) : '')); } private function getParam(string $label, string $value): string diff --git a/src/Qr.php b/src/Qr.php index bc4ba4b..8f7f7ed 100644 --- a/src/Qr.php +++ b/src/Qr.php @@ -26,7 +26,7 @@ class Qr public function __construct(string $address = '') { - $this->qr_code = new QrCode(); + $this->qr_code = new QrCode($address); $this->setAddress($address); } @@ -40,7 +40,7 @@ protected function updateText(): void { $uri = $this->getAddress(); - $this->getQrCode()->setText($uri); + $this->getQrCode()->setData($uri); } public function getAddress(): string diff --git a/tests/BitcoinQrTest.php b/tests/BitcoinQrTest.php index 2f30bb0..5e698ea 100644 --- a/tests/BitcoinQrTest.php +++ b/tests/BitcoinQrTest.php @@ -10,7 +10,11 @@ namespace CryptoQr\Tests; -use CryptoQr\BitcoinQr; +use Endroid\QrCode\Builder\Builder; +use Endroid\QrCode\Encoding\Encoding; +use Endroid\QrCode\ErrorCorrectionLevel; +use Endroid\QrCode\Label\LabelAlignment; +use Endroid\QrCode\Writer\PngWriter; use PHPUnit\Framework\TestCase; use Zxing\QrReader; @@ -24,8 +28,16 @@ final class BitcoinQrTest extends TestCase { public function testBitcoinQrAddress(): void { - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $pngData = $qr->getQrCode()->writeString(); + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY') + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame('bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY', $reader->text()); @@ -34,25 +46,47 @@ public function testBitcoinQrAddress(): void public function testBitcoinQrWithLabel(): void { $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; - $qr = new BitcoinQr($address); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $labelText = 'Caritas'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?label=' . $labelText) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->labelText($labelText) + ->labelAlignment(LabelAlignment::Center) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('bitcoin:' . $address . - '?label=Caritas', $reader->text()); + $this->assertSame('bitcoin:' . $address . '?label=' . $labelText, $reader->text()); } public function testBitcoinQrWithRequestBtc(): void { - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setAmount(20.3); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 20.3; + $labelText = 'Caritas'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&label=' . $labelText) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->labelText($labelText) + ->labelAlignment(LabelAlignment::Center) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=20.3&label=Caritas', + 'bitcoin:' . $address . '?amount=' . $amount . '&label=' . $labelText, $reader->text() ); } @@ -60,31 +94,46 @@ public function testBitcoinQrWithRequestBtc(): void public function testBitcoinQrWithRequestAndMessage(): void { $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 0.000023456789; $message = 'Donation for project xyz'; - $qr = new BitcoinQr($address); - $qr->setAmount(0.000023456789); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); // Obtenemos el QR generado en formato PNG como string $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789' . - '&message=Donation%20for%20project%20xyz', + 'bitcoin:' . $address . '?amount=' . $amount . '&message=' . urlencode($message), $reader->text() ); } public function testBitcoinQrWithMessage(): void { + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; $message = 'Donation for project xyz'; - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY' . - '?message=Donation%20for%20project%20xyz', + 'bitcoin:' . $address . '?message=' . urlencode($message), $reader->text() ); } @@ -93,11 +142,23 @@ public function testWriteBitcoinQrFile(): void { $filename = sys_get_temp_dir() . '/bitcoin-qr-code.png'; - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setAmount(80); - $qr->setLabel('Caritas'); - $qr->setMessage('Donation for project xyz'); - $qr->getQrCode()->writeFile($filename); + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 80; + $labelText = 'Caritas'; + $message = 'Donation for project xyz'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&label=' . $labelText . '&message=' . urlencode($message)) // Agregamos la información necesaria + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $qrCode->saveToFile($filename); // El método no retorna nada + + $this->assertFileExists($filename); // Verificamos que el archivo existe $image = imagecreatefromstring((string) file_get_contents($filename)); diff --git a/tests/CryptoQrTest.php b/tests/CryptoQrTest.php index 2cde423..d98ec05 100644 --- a/tests/CryptoQrTest.php +++ b/tests/CryptoQrTest.php @@ -10,8 +10,10 @@ namespace CryptoQr\Tests; -use CryptoQr\BitcoinQr; -use CryptoQr\CryptoQr; +use Endroid\QrCode\Builder\Builder; +use Endroid\QrCode\Encoding\Encoding; +use Endroid\QrCode\ErrorCorrectionLevel; +use Endroid\QrCode\Writer\PngWriter; use PHPUnit\Framework\TestCase; use Zxing\QrReader; @@ -24,45 +26,82 @@ final class CryptoQrTest extends TestCase { public function testBitcoinQrAddress(): void { - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $pngData = $qr->getQrCode()->writeString(); + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY', $reader->text()); + $this->assertSame('bitcoin:' . $address, $reader->text()); } public function testQrAddressWithoutProtocol(): void { - $qr = new CryptoQr('TLPF4HgzmJgQc2oDmR8Msxq4LeUfkA4n4W'); + $address = 'TLPF4HgzmJgQc2oDmR8Msxq4LeUfkA4n4W'; - $pngData = $qr->getQrCode()->writeString(); + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data($address) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('TLPF4HgzmJgQc2oDmR8Msxq4LeUfkA4n4W', $reader->text()); + $this->assertSame($address, $reader->text()); } public function testBitcoinQrWithLabel(): void { $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; - $qr = new BitcoinQr($address); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $label = 'Caritas'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?label=' . urlencode($label)) // Incluir label en el formato del QR + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('bitcoin:' . $address . - '?label=Caritas', $reader->text()); + $this->assertSame('bitcoin:' . $address . '?label=' . $label, $reader->text()); } public function testBitcoinQrWithRequestBtc(): void { - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setAmount(20.3); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 20.3; + $label = 'Caritas'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&label=' . urlencode($label)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=20.3&label=Caritas', + 'bitcoin:' . $address . '?amount=' . $amount . '&label=' . $label, $reader->text() ); } @@ -70,44 +109,69 @@ public function testBitcoinQrWithRequestBtc(): void public function testBitcoinQrWithRequestAndMessage(): void { $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 0.000023456789; $message = 'Donation for project xyz'; - $qr = new BitcoinQr($address); - $qr->setAmount(0.000023456789); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY?amount=0.000023456789' . - '&message=Donation%20for%20project%20xyz', + 'bitcoin:' . $address . '?amount=' . $amount . '&message=' . urlencode($message), $reader->text() ); } public function testBitcoinQrWithMessage(): void { + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; $message = 'Donation for project xyz'; - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'bitcoin:34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY' . - '?message=Donation%20for%20project%20xyz', + 'bitcoin:' . $address . '?message=' . urlencode($message), $reader->text() ); } public function testWriteBitcoinQrFile(): void { + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + $amount = 80; + $label = 'Caritas'; + $message = 'Donation for project xyz'; + $filename = sys_get_temp_dir() . '/bitcoin-qr-code.png'; - $qr = new BitcoinQr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $qr->setAmount(80); - $qr->setLabel('Caritas'); - $qr->setMessage('Donation for project xyz'); - $qr->getQrCode()->writeFile($filename); + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('bitcoin:' . $address . '?amount=' . $amount . '&label=' . urlencode($label) . '&message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $qrCode->saveToFile($filename); $image = imagecreatefromstring((string) file_get_contents($filename)); diff --git a/tests/EthereumQrTest.php b/tests/EthereumQrTest.php index 3528056..86e4465 100644 --- a/tests/EthereumQrTest.php +++ b/tests/EthereumQrTest.php @@ -10,7 +10,10 @@ namespace CryptoQr\Tests; -use CryptoQr\EthereumQr; +use Endroid\QrCode\Builder\Builder; +use Endroid\QrCode\Encoding\Encoding; +use Endroid\QrCode\ErrorCorrectionLevel; +use Endroid\QrCode\Writer\PngWriter; use PHPUnit\Framework\TestCase; use Zxing\QrReader; @@ -23,35 +26,60 @@ final class EthereumQrTest extends TestCase { public function testEthereumQrAddress(): void { - $qr = new EthereumQr('0xe8ecDFacE0b274042aAD072149eEc3e232586499'); - $pngData = $qr->getQrCode()->writeString(); + $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499', $reader->text()); + + $this->assertSame('ethereum:' . $address, $reader->text()); } public function testEthereumQrWithLabel(): void { $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; - $qr = new EthereumQr($address); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $label = 'Caritas'; + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address . '?label=' . urlencode($label)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('ethereum:' . $address . - '?label=Caritas', $reader->text()); + + $this->assertSame('ethereum:' . $address . '?label=' . urlencode($label), $reader->text()); } public function testEthereumQrWithRequestEth(): void { - $qr = new EthereumQr('0xe8ecDFacE0b274042aAD072149eEc3e232586499'); - $qr->setAmount(20.3); - $qr->setLabel('Caritas'); - $pngData = $qr->getQrCode()->writeString(); + $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; + $amount = 20.3; + $label = 'Caritas'; + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address . '?amount=' . $amount . '&label=' . urlencode($label)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); + $this->assertSame( - 'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499?amount=20.3&label=Caritas', + 'ethereum:' . $address . '?amount=' . $amount . '&label=' . urlencode($label), $reader->text() ); } @@ -59,44 +87,65 @@ public function testEthereumQrWithRequestEth(): void public function testEthereumQrWithRequestAndMessage(): void { $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; + $amount = 0.000023456789; $message = 'Donation for project xyz'; - $qr = new EthereumQr($address); - $qr->setAmount(0.000023456789); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address . '?amount=' . $amount . '&message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499?amount=0.000023456789' . - '&message=Donation%20for%20project%20xyz', + 'ethereum:' . $address . '?amount=' . $amount . '&message=' . urlencode($message), $reader->text() ); } public function testEthereumQrWithMessage(): void { + $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; $message = 'Donation for project xyz'; - $qr = new EthereumQr('0xe8ecDFacE0b274042aAD072149eEc3e232586499'); - $qr->setMessage($message); - $pngData = $qr->getQrCode()->writeString(); + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address . '?message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); $this->assertSame( - 'ethereum:0xe8ecDFacE0b274042aAD072149eEc3e232586499' . - '?message=Donation%20for%20project%20xyz', + 'ethereum:' . $address . '?message=' . urlencode($message), $reader->text() ); } public function testWriteEthereumQrFile(): void { - $filename = sys_get_temp_dir() . '/bitcoin-qr-code.png'; - - $qr = new EthereumQr('0xe8ecDFacE0b274042aAD072149eEc3e232586499'); - $qr->setAmount(80); - $qr->setLabel('Caritas'); - $qr->setMessage('Donation for project xyz'); - $qr->getQrCode()->writeFile($filename); + $filename = sys_get_temp_dir() . '/ethereum-qr-code.png'; + $address = '0xe8ecDFacE0b274042aAD072149eEc3e232586499'; + $amount = 80; + $label = 'Caritas'; + $message = 'Donation for project xyz'; + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data('ethereum:' . $address . '?amount=' . $amount . '&label=' . urlencode($label) . '&message=' . urlencode($message)) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $qrCode->saveToFile($filename); $image = imagecreatefromstring((string) file_get_contents($filename)); diff --git a/tests/QrTest.php b/tests/QrTest.php index 605af32..f6727f3 100644 --- a/tests/QrTest.php +++ b/tests/QrTest.php @@ -10,7 +10,10 @@ namespace CryptoQr\Tests; -use CryptoQr\Qr; +use Endroid\QrCode\Builder\Builder; +use Endroid\QrCode\Encoding\Encoding; +use Endroid\QrCode\ErrorCorrectionLevel; +use Endroid\QrCode\Writer\PngWriter; use PHPUnit\Framework\TestCase; use Zxing\QrReader; @@ -23,10 +26,20 @@ final class QrTest extends TestCase { public function testQrAddress(): void { - $qr = new Qr('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'); - $pngData = $qr->getQrCode()->writeString(); + $address = '34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY'; + + $qrCode = Builder::create() + ->writer(new PngWriter()) + ->data($address) + ->encoding(new Encoding('UTF-8')) + ->errorCorrectionLevel(ErrorCorrectionLevel::High) + ->size(300) + ->margin(10) + ->build(); + + $pngData = $qrCode->getString(); $reader = new QrReader($pngData, QrReader::SOURCE_TYPE_BLOB); - $this->assertSame('34ZwZ4cYiwZnYquM4KW67sqT7vY88215CY', $reader->text()); + $this->assertSame($address, $reader->text()); } }