Skip to content

Commit

Permalink
Fix code coverage (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Sep 27, 2021
1 parent 49d57cb commit 7164329
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Helper/CacheableBicDictionaryTrait.php
Expand Up @@ -34,7 +34,9 @@ private function cacheResult(IbanInterface $iban, string $bic): void
private function getCached(IbanInterface $iban): string
{
if (!$this->isCached($iban)) {
// @codeCoverageIgnoreStart
throw new CacheException("There is no cache for IBAN {$iban}");
// @codeCoverageIgnoreEnd
}

return $this->cache[$iban->asString()];
Expand Down
10 changes: 10 additions & 0 deletions src/QrPayment.php
Expand Up @@ -435,6 +435,16 @@ public function setPayeeAddressLine2(string $addressLine): QrPayment
return $this;
}

public function getPayeeAddressLine1(): string
{
return $this->payeeAddressLine1;
}

public function getPayeeAddressLine2(): string
{
return $this->payeeAddressLine2;
}

public function getXzBinaryLocator(): XzBinaryLocatorInterface
{
return $this->xzBinaryLocator;
Expand Down
4 changes: 4 additions & 0 deletions src/Xz/XzBinaryLocator.php
Expand Up @@ -21,10 +21,14 @@ public function getXzBinary(): string
if ($this->path === null) {
exec('which xz', $output, $return);
if ($return !== 0) {
// @codeCoverageIgnoreStart
throw new QrPaymentException("'xz' binary not found in PATH, specify it using setXzBinary()");
// @codeCoverageIgnoreEnd
}
if (!isset($output[0])) {
// @codeCoverageIgnoreStart
throw new QrPaymentException("'xz' binary not found in PATH, specify it using setXzBinary()");
// @codeCoverageIgnoreEnd
}
$this->path = $output[0];
}
Expand Down
54 changes: 54 additions & 0 deletions tests/Exception/InvalidTypeExceptionTest.php
@@ -0,0 +1,54 @@
<?php

namespace rikudou\SkQrPayment\Tests\Exception;

use rikudou\SkQrPayment\Exception\InvalidTypeException;
use PHPUnit\Framework\TestCase;
use stdClass;

class InvalidTypeExceptionTest extends TestCase
{
public function testMessage()
{
self::assertEquals(
$this->getExpectedMessage('int', 'string'),
$this->getMessage('int', '')
);
self::assertEquals(
$this->getExpectedMessage("int' or 'string", 'array'),
$this->getMessage(['int', 'string'], [])
);
self::assertEquals(
$this->getExpectedMessage('string', 'integer'),
$this->getMessage('string', 5)
);
self::assertEquals(
$this->getExpectedMessage('5', 'double'),
$this->getMessage(5, 0.1)
);
self::assertEquals(
$this->getExpectedMessage('string', 'integer'),
$this->getMessage(new class {
public function __toString()
{
return 'string';
}
}, 5)
);

self::assertEquals(
$this->getExpectedMessage('string', 'stdClass'),
$this->getMessage('string', new stdClass())
);
}

private function getExpectedMessage(string $expected, string $got): string
{
return "Expected '{$expected}', got '{$got}'";
}

private function getMessage($expected, $actual): string
{
return (new InvalidTypeException($expected, $actual))->getMessage();
}
}
20 changes: 16 additions & 4 deletions tests/QrPaymentTest.php
Expand Up @@ -6,13 +6,16 @@
use DateTimeInterface;
use Endroid\QrCode\QrCode;
use InvalidArgumentException;
use Rikudou\BySquare\Decoder\PayBySquareDecoder;
use Rikudou\BySquare\VO\DecodedBySquareData;
use Rikudou\Iban\Iban\IBAN;
use rikudou\SkQrPayment\Exception\InvalidTypeException;
use rikudou\SkQrPayment\Exception\QrPaymentException;
use rikudou\SkQrPayment\Payment\QrPaymentOptions;
use rikudou\SkQrPayment\QrPayment;
use PHPUnit\Framework\TestCase;
use rikudou\SkQrPayment\Xz\XzBinaryLocator;
use stdClass;
use TypeError;

class QrPaymentTest extends TestCase
Expand Down Expand Up @@ -92,7 +95,7 @@ public function testSetOptions()
// test that values from array are type checked
$this->expectException(TypeError::class);
$this->instance->setOptions([
QrPaymentOptions::VARIABLE_SYMBOL => new \stdClass(),
QrPaymentOptions::VARIABLE_SYMBOL => new stdClass(),
]);
}

Expand Down Expand Up @@ -226,7 +229,7 @@ public function __toString()
self::assertSame('123', $this->instance->getVariableSymbol());

$this->expectException(TypeError::class);
$this->instance->setVariableSymbol(new \stdClass());
$this->instance->setVariableSymbol(new stdClass());
}

public function testSetSpecificSymbol()
Expand All @@ -247,7 +250,7 @@ public function __toString()
self::assertSame('123', $this->instance->getSpecificSymbol());

$this->expectException(TypeError::class);
$this->instance->setSpecificSymbol(new \stdClass());
$this->instance->setSpecificSymbol(new stdClass());
}

public function testSetConstantSymbol()
Expand All @@ -268,6 +271,15 @@ public function __toString()
self::assertSame('123', $this->instance->getConstantSymbol());

$this->expectException(TypeError::class);
$this->instance->setConstantSymbol(new \stdClass());
$this->instance->setConstantSymbol(new stdClass());
}

public function testSetPayeeAddressLine()
{
$this->instance->setPayeeAddressLine1('123');
$this->instance->setPayeeAddressLine2('456');

self::assertEquals('123', $this->instance->getPayeeAddressLine1());
self::assertEquals('456', $this->instance->getPayeeAddressLine2());
}
}

0 comments on commit 7164329

Please sign in to comment.