Skip to content

Commit

Permalink
refactor: updated endroid/qr-code
Browse files Browse the repository at this point in the history
  • Loading branch information
petrknap committed Oct 12, 2023
1 parent da11ea5 commit 0b2bca2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ RUN docker-php-ext-install \

WORKDIR /app
COPY . .
RUN composer install
RUN composer update --prefer-lowest
Empty file modified README.md
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"name": "petrknap/spayd-qr",
"require": {
"php": ">=8.0",
"endroid/qr-code": "^3.5",
"endroid/qr-code": "^4.1",
"moneyphp/money": "^4.0",
"sunfoxcz/spayd-php": "^2.0"
},
Expand Down
36 changes: 18 additions & 18 deletions src/SpaydQr.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace PetrKnap\SpaydQr;

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Builder\BuilderInterface;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\Writer\PngWriter;
use Endroid\QrCode\Writer\WriterInterface;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Money\Currencies\ISOCurrencies;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Money;
Expand All @@ -15,7 +18,7 @@ class SpaydQr implements SpaydQrInterface
/** @internal */
protected function __construct(
/** @internal */ protected Spayd $spayd,
private QrCode $qrCode,
/** @internal */ protected BuilderInterface $qrCodeBuilder,
string $iban,
Money $money
) {
Expand All @@ -27,12 +30,11 @@ protected function __construct(

public static function create(string $iban, Money $money, WriterInterface $writer = null): self
{
$qrCode = new QrCode();
$qrCode->setWriter($writer ?: new PngWriter());

return new self(
new Spayd(),
$qrCode,
Builder::create()
->writer($writer ?: new PngWriter())
->encoding(new Encoding('UTF-8')),
$iban,
$money
);
Expand Down Expand Up @@ -80,47 +82,45 @@ public function setInvoice(

public function setWriter(WriterInterface $writer): self
{
$this->qrCode->setWriter($writer);
$this->qrCodeBuilder->writer($writer);

return $this;
}

public function getContentType(): string
{
return $this->prepareQrCode(null, null, null)->getContentType();
return $this->buildQrCode(null, null)->getMimeType();
}

public function getContent(int $size = self::QR_SIZE, int $margin = self::QR_MARGIN): string
{
return $this->prepareQrCode($this->spayd, $size, $margin)->writeString();
return $this->buildQrCode($size, $margin)->getString();
}

public function getDataUri(int $size = self::QR_SIZE, int $margin = self::QR_MARGIN): string
{
return $this->prepareQrCode($this->spayd, $size, $margin)->writeDataUri();
return $this->buildQrCode($size, $margin)->getDataUri();
}

public function writeFile(string $path, int $size = self::QR_SIZE, int $margin = self::QR_MARGIN): void
{
$this->prepareQrCode($this->spayd, $size, $margin)->writeFile($path);
$this->buildQrCode($size, $margin)->saveToFile($path);
}

/** @internal */
protected function prepareQrCode(?Spayd $spayd, ?int $size, ?int $margin): QrCode
protected function buildQrCode(?int $size, ?int $margin): ResultInterface
{
if ($spayd !== null) {
$this->qrCode->setText($spayd->generate());
}
$this->qrCodeBuilder->data($this->spayd->generate());

if ($size !== null) {
$this->qrCode->setSize($size);
$this->qrCodeBuilder->size($size);
}

if ($margin !== null) {
$this->qrCode->setMargin($margin);
$this->qrCodeBuilder->margin($margin);
}

return $this->qrCode;
return $this->qrCodeBuilder->build();
}

private function getAmount(Money $money): string
Expand Down
1 change: 1 addition & 0 deletions src/SpaydQrInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function setInvoice(
?string $buyerVatIdentificationNumber,
?string $description
): self;
/** @todo create own enum of writers */
public function setWriter(WriterInterface $writer): self;

public function getContentType(): string;
Expand Down
2 changes: 1 addition & 1 deletion tests/ExamplesTest/readme_1.html
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEs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EEKYEEKYEEKYEEKYEELYB3XCnRvGF8oHuE8YxpDN6UOOLdhZQN/56Nbq+O8bhT8I4VMXZIeM/KnncP7ghwzvnmFYjkKYEEKYEEKYEEKYEEKYEEKYEEJYfVNv+3789jJu++nzQ8ruC+2vE9Tq3e0XHDK9D2Jn/RfMr1zXOLM+y3IUwoQQwoQQwoQQwoQQwoQQwoQQwr5pnXDIKe3te/9r7mnh/lW1dyHaLW5553H2775pCBd2FppVtP901hL/h/dlOQphQghhQghhQghhQghhQghhQghh37ROWNv6XWt1XiuFt7cFWKi9n7BzDhfamyQstM/Gu28awlpd+JSl5JfqbDz1HI5qJmA5CmFCCGFCCGFCCGFCCGFCCGFCCGH1OmH7rvCdJ4zXtHfIr5Wn23vd7+wzUNuq395Xv11tNj51Zv3CkKrrEPN3he+syLcbMowHsRyFMCGEMCGEMCGEMCGEMCGEMCGEsMtxHO2nz+/Uvs18ob3evbCzgL7zgtfr9e3t7a9/2vl7DRnG/x7d95r987rdbsc/DPmuxacW2ocx5IK1Wz73MCxHIUwIIUwIIUwIIUwIIUwIIUwIIezyiMII8Hn+E0LYfwEqBxvq+lzjewAAAABJRU5ErkJggg==">
125 changes: 65 additions & 60 deletions tests/SpaydQrTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PetrKnap\SpaydQr\Test;

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Builder\BuilderInterface;
use Endroid\QrCode\Writer\Result\ResultInterface;
use Endroid\QrCode\Writer\SvgWriter;
use Endroid\QrCode\Writer\WriterInterface;
use Money\Money;
Expand Down Expand Up @@ -30,16 +32,13 @@ public function testFactoryWorks()
public function testSetWriterWorks()
{
$writer = $this->getMockBuilder(WriterInterface::class)->getMock();
$qrCode = $this->getMockBuilder(QrCode::class)
->disableOriginalConstructor()
->setMethods(['setWriter'])
->getMock();
$qrCode->expects($this->once())
->method('setWriter')
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('writer')
->with($writer)
->willReturnSelf();

$this->getSpaydQr(null, $qrCode)->setWriter($writer);
$this->getSpaydQr(null, $qrCodeBuilder)->setWriter($writer);
}

public function testSetVariableSymbolWorks()
Expand Down Expand Up @@ -97,17 +96,18 @@ public function testGetContentTypeWorks()
{
$expectedContentType = 'Expected content type';

$qrCode = $this->getMockBuilder(QrCode::class)
->disableOriginalConstructor()
->setMethods(['getContentType'])
->getMock();
$qrCode->expects($this->once())
->method('getContentType')
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeResult = $this->getMockBuilder(ResultInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('build')
->willReturn($qrCodeResult);
$qrCodeResult->expects($this->once())
->method('getMimeType')
->willReturn($expectedContentType);

$this->assertEquals(
$expectedContentType,
$this->getSpaydQr(null, $qrCode)->getContentType()
$this->getSpaydQr(null, $qrCodeBuilder)->getContentType()
);
}

Expand All @@ -125,26 +125,27 @@ public function testGetContentWorks(?int $expectedSize, ?int $expectedMargin)
->method('generate')
->willReturn($expectedSPayD);

$qrCode = $this->getMockBuilder(QrCode::class)
->disableOriginalConstructor()
->setMethods(['setSize', 'setMargin', 'setText', 'writeString'])
->getMock();
$qrCode->expects($this->once())
->method('setSize')
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeResult = $this->getMockBuilder(ResultInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('size')
->with($expectedSize ?: SpaydQr::QR_SIZE);
$qrCode->expects($this->once())
->method('setMargin')
$qrCodeBuilder->expects($this->once())
->method('margin')
->with($expectedMargin ?: SpaydQr::QR_MARGIN);
$qrCode->expects($this->once())
->method('setText')
$qrCodeBuilder->expects($this->once())
->method('data')
->with($expectedSPayD);
$qrCode->expects($this->once())
->method('writeString')
$qrCodeBuilder->expects($this->once())
->method('build')
->willReturn($qrCodeResult);
$qrCodeResult->expects($this->once())
->method('getString')
->willReturn($expectedContent);

$this->assertEquals(
$expectedContent,
$this->getSpaydQr($spayd, $qrCode)->getContent(...$this->trimArgs([$expectedSize, $expectedMargin]))
$this->getSpaydQr($spayd, $qrCodeBuilder)->getContent(...$this->trimArgs([$expectedSize, $expectedMargin]))
);
}

Expand All @@ -171,26 +172,27 @@ public function testGetDataUriWorks(?int $expectedSize, ?int $expectedMargin)
->method('generate')
->willReturn($expectedSPayD);

$qrCode = $this->getMockBuilder(QrCode::class)
->disableOriginalConstructor()
->setMethods(['setSize', 'setMargin', 'setText', 'writeDataUri'])
->getMock();
$qrCode->expects($this->once())
->method('setSize')
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeResult = $this->getMockBuilder(ResultInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('size')
->with($expectedSize ?: SpaydQr::QR_SIZE);
$qrCode->expects($this->once())
->method('setMargin')
$qrCodeBuilder->expects($this->once())
->method('margin')
->with($expectedMargin ?: SpaydQr::QR_MARGIN);
$qrCode->expects($this->once())
->method('setText')
$qrCodeBuilder->expects($this->once())
->method('data')
->with($expectedSPayD);
$qrCode->expects($this->once())
->method('writeDataUri')
$qrCodeBuilder->expects($this->once())
->method('build')
->willReturn($qrCodeResult);
$qrCodeResult->expects($this->once())
->method('getDataUri')
->willReturn($expectedDataUri);

$this->assertEquals(
$expectedDataUri,
$this->getSpaydQr($spayd, $qrCode)->getDataUri(...$this->trimArgs([$expectedSize, $expectedMargin]))
$this->getSpaydQr($spayd, $qrCodeBuilder)->getDataUri(...$this->trimArgs([$expectedSize, $expectedMargin]))
);
}

Expand All @@ -213,24 +215,25 @@ public function testWriteFileWorks(?int $expectedSize, ?int $expectedMargin)
->method('generate')
->willReturn($expectedSPayD);

$qrCode = $this->getMockBuilder(QrCode::class)
->disableOriginalConstructor()
->setMethods(['setSize', 'setMargin', 'setText', 'writeFile'])
->getMock();
$qrCode->expects($this->once())
->method('setSize')
$qrCodeBuilder = $this->getMockBuilder(BuilderInterface::class)->getMock();
$qrCodeResult = $this->getMockBuilder(ResultInterface::class)->getMock();
$qrCodeBuilder->expects($this->once())
->method('size')
->with($expectedSize ?: SpaydQr::QR_SIZE);
$qrCode->expects($this->once())
->method('setMargin')
$qrCodeBuilder->expects($this->once())
->method('margin')
->with($expectedMargin ?: SpaydQr::QR_MARGIN);
$qrCode->expects($this->once())
->method('setText')
$qrCodeBuilder->expects($this->once())
->method('data')
->with($expectedSPayD);
$qrCode->expects($this->once())
->method('writeFile')
$qrCodeBuilder->expects($this->once())
->method('build')
->willReturn($qrCodeResult);
$qrCodeResult->expects($this->once())
->method('saveToFile')
->with($expectedPath);

$this->getSpaydQr($spayd, $qrCode)->writeFile(...$this->trimArgs([$expectedPath, $expectedSize, $expectedMargin]));
$this->getSpaydQr($spayd, $qrCodeBuilder)->writeFile(...$this->trimArgs([$expectedPath, $expectedSize, $expectedMargin]));
}

public function dataWriteFileWorks()
Expand All @@ -240,7 +243,7 @@ public function dataWriteFileWorks()

public function testEndToEnd()
{
$spaydQr = $this->getSpaydQr(new Spayd(), new QrCode())
$spaydQr = $this->getSpaydQr(null, null)
->setWriter(new SvgWriter())
->setVariableSymbol(123)
->setInvoice(
Expand All @@ -254,14 +257,14 @@ public function testEndToEnd()
);

$this->assertNotEmpty($spaydQr->getSpayd()->generate());
$this->assertNotEmpty($spaydQr->getQrCode()->getData());
$this->assertNotEmpty($spaydQr->getQrCodeBuilder()->build()->getDataUri());
}

private function getSpaydQr(?Spayd $spayd, ?QrCode $qrCode)
private function getSpaydQr(?Spayd $spayd, ?BuilderInterface $qrCodeBuilder)
{
return new class (
$spayd ?: new Spayd(),
$qrCode ?: new QrCode(),
$qrCodeBuilder ?: Builder::create(),
self::IBAN,
Money::EUR(100)
) extends SpaydQr {
Expand All @@ -275,9 +278,11 @@ public function getSpayd(): Spayd
return $this->spayd;
}

public function getQrCode(): QrCode
public function getQrCodeBuilder(): BuilderInterface
{
return $this->prepareQrCode($this->spayd, null, null);
$this->buildQrCode(null, null);

return $this->qrCodeBuilder;
}
};
}
Expand Down

0 comments on commit 0b2bca2

Please sign in to comment.