Skip to content

Commit

Permalink
Test with endroid/qr-code v5
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Feb 29, 2024
1 parent 5367b44 commit 9c0a05e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 52 deletions.
30 changes: 13 additions & 17 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
name: Tests
on: [push, pull_request]
jobs:
symfony:
name: PHP ${{ matrix.php-versions }} ${{ matrix.composer-flags }}
build:
name: PHP ${{ matrix.php-versions }} (${{ matrix.deps }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- php-versions: '8.1'
composer-flags: '--prefer-lowest'
deps: 'lowest'
php-versions:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
deps: ['highest']
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, curl, pcov
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer update -n --prefer-dist ${{ matrix.composer-flags }}
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.deps }}
- name: Run Tests
run: vendor/bin/phpunit
- name: Upload coverage to Codecov
if: ${{ matrix.php-versions == 8.1 }}
uses: codecov/codecov-action@v1
if: ${{ matrix.php-versions == 8.3 }}
uses: codecov/codecov-action@v4
- name: Run mutation tests
if: ${{ matrix.php-versions == 8.1 }}
if: ${{ matrix.php-versions == 8.3 }}
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
run: vendor/bin/infection --ignore-msi-with-no-mutations --min-covered-msi=100 --min-msi=100 -s -j4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/phpunit.xml
/clover.xml
/.phpunit.result.cache
/.phpunit.cache
/infection.log
/infection.json
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"endroid/qr-code": "^4.0",
"infection/infection": "~0.26.14"
"phpunit/phpunit": "^10",
"endroid/qr-code": "^4 || ^5",
"infection/infection": "~0.27.9"
},
"license": "MIT",
"autoload": {
Expand All @@ -25,7 +25,7 @@
"psr-4": { "IonBazan\\PaymentQR\\Poland\\Tests\\": "tests/" }
},
"suggest": {
"endroid/qr-code": "Allows generating QR code images"
"endroid/qr-code": "^4 | ^5 Allows generating QR code images"
},
"config": {
"allow-plugins": {
Expand Down
37 changes: 17 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Library Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging/>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
<testsuites>
<testsuite name="Library Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
23 changes: 12 additions & 11 deletions tests/QrPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Endroid\QrCode\ErrorCorrectionLevel;
use IonBazan\PaymentQR\Poland\QrPayment;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;

class QrPaymentTest extends TestCase
Expand Down Expand Up @@ -40,28 +42,22 @@ public function testItGeneratesValidQrStringForExampleInput(): void
);
}

/**
* @dataProvider documentationExamplesProvider
*/
#[DataProvider('documentationExamplesProvider')]
public function testItGeneratesValidQrString(string $expectedResult, QrPayment $paymentQr): void
{
$this->assertSame($expectedResult, $paymentQr->getQrString());
$this->assertEquals($paymentQr, QrPayment::fromQrString($expectedResult));
}

/**
* @dataProvider documentationExamplesProvider
*/
#[DataProvider('documentationExamplesProvider')]
public function testItCreatesValidObjectFromString(string $inputString, QrPayment $expectedPayment): void
{
$payment = QrPayment::fromQrString($inputString);
$this->assertEquals($expectedPayment, $payment);
$this->assertSame($inputString, $payment->getQrString());
}

/**
* @runInSeparateProcess
*/
#[RunInSeparateProcess]
public function testItGeneratesQrImage(): void
{
$payment = new QrPayment(
Expand All @@ -81,7 +77,12 @@ public function testItGeneratesQrImage(): void
'5214349636|PL|24160000035175530643314956|012345|Testowy odbiorca|Tytuł płatności|11223344|990066|',
$qrCode->getData()
);
$correctionLevel = new ErrorCorrectionLevel\ErrorCorrectionLevelLow();

if (class_exists(ErrorCorrectionLevel\ErrorCorrectionLevelLow::class)) {
$correctionLevel = new ErrorCorrectionLevel\ErrorCorrectionLevelLow();
} else {
$correctionLevel = ErrorCorrectionLevel::Low;
}

$this->assertSame(250, $qrCode->getSize());
$this->assertEquals($correctionLevel, $qrCode->getErrorCorrectionLevel());
Expand Down Expand Up @@ -134,7 +135,7 @@ public function testItStripsInvalidCharactersAndTrims(): void
);
}

public function documentationExamplesProvider(): array
public static function documentationExamplesProvider(): array
{
return [
'2D dla Odbiorcy typ 1 z kwotą płatności bez możliwości edycji' => [
Expand Down

0 comments on commit 9c0a05e

Please sign in to comment.