Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade: PHPUnit 10 #271

Merged
merged 8 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
run: composer update --${{ matrix.stability }} --prefer-dist --no-progress

- name: Execute tests in default environment
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit

- name: Execute tests in hardened environment
run: php -d allow_url_fopen=0 -d memory_limit=256M -d register_globals=0 vendor/bin/phpunit --verbose
run: php -d allow_url_fopen=0 -d memory_limit=256M -d register_globals=0 vendor/bin/phpunit

code_checks:
runs-on: ubuntu-20.04
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
"symfony/polyfill-mbstring": "^1.30"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"dg/bypass-finals": "^1.3",
"dms/phpunit-arraysubset-asserts": "^0.2",
"phpunit/phpunit": "^10.5",
"dg/bypass-finals": "^1.8",
"dms/phpunit-arraysubset-asserts": "^0.5",
"fpdf/fpdf": "^1.85",
"friendsofphp/php-cs-fixer": "^3.15",
"khanamiryan/qrcode-detector-decoder": "^1.0.3",
"khanamiryan/qrcode-detector-decoder": "^2.0.2",
"phpstan/phpstan": "^1.11-dev",
"setasign/fpdi": "^2.3.5",
"setasign/fpdf": "^1.8.2",
"tecnickcom/tcpdf": "^6.3.2",
"rector/rector": "^1.2"
"rector/rector": "^1.2",
"nunomaduro/mock-final-classes": "^1.2"
},
"scripts": {
"cs:fix": "vendor/bin/php-cs-fixer fix --verbose",
"cs:diff": "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose",
"phpstan": "vendor/bin/phpstan analyse",
"phpunit": "vendor/bin/phpunit --verbose",
"phpunit": "vendor/bin/phpunit",
"rector": "vendor/bin/rector"
},
"conflict": {
Expand Down
11 changes: 7 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
bootstrap = "vendor/autoload.php"
colors = "true"
convertDeprecationsToExceptions = "false"
bootstrap="vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<testsuites>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Sprain\Tests\SwissQrBill\Constraints;

use DG\BypassFinals;
use PHPUnit\Framework\Attributes\DataProvider;
use Sprain\SwissQrBill\Constraint\ValidCreditorInformationPaymentReferenceCombination;
use Sprain\SwissQrBill\Constraint\ValidCreditorInformationPaymentReferenceCombinationValidator;
use Sprain\SwissQrBill\DataGroup\Element\CreditorInformation;
Expand Down Expand Up @@ -32,66 +32,60 @@ public function testRandomClassIsValid()
$this->assertNoViolation();
}

/**
* @dataProvider emptyQrBillMocksProvider
*/
public function testEmptyQrBillValuesAreValid(QrBill $qrBillMock)
#[DataProvider('emptyQrBillMocksProvider')]
public function testEmptyQrBillValuesAreValid(bool $createCreditorInformationMock, bool $createPaymentReferenceMock)
{
$qrBillMock = $this->getQrBillMock(
($createCreditorInformationMock) ? $this->getCreditorInformationMock() : null,
($createPaymentReferenceMock) ? $this->getPaymentReferenceMock() : null,
);

$this->validator->validate($qrBillMock, new ValidCreditorInformationPaymentReferenceCombination());

$this->assertNoViolation();
}

public function emptyQrBillMocksProvider(): array
public static function emptyQrBillMocksProvider(): array
{
BypassFinals::enable();

return [
[$this->getQrBillMock()],
[$this->getQrBillMock(
$this->getCreditorInformationMock(),
null
)],
[$this->getQrBillMock(
null,
$this->getPaymentReferenceMock()
)]
// createCreditorInformationMock, createPaymentReferenceMock
[false, false,],
[true, false,],
[false, true,],
];
}

/**
* @dataProvider validCombinationsQrBillMocksProvider
*/
public function testValidCombinations(QrBill $qrBillMock)
#[DataProvider('validCombinationsQrBillMocksProvider')]
public function testValidCombinations(bool $containsQrIban, string $paymentReferenceType)
{
$qrBillMock = $this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', $containsQrIban),
$this->getPaymentReferenceMock($paymentReferenceType)
);

$this->validator->validate($qrBillMock, new ValidCreditorInformationPaymentReferenceCombination());

$this->assertNoViolation();
}

public function validCombinationsQrBillMocksProvider(): array
public static function validCombinationsQrBillMocksProvider(): array
{
return [
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', true),
$this->getPaymentReferenceMock(PaymentReference::TYPE_QR)
)],
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', false),
$this->getPaymentReferenceMock(PaymentReference::TYPE_SCOR)
)],
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', false),
$this->getPaymentReferenceMock(PaymentReference::TYPE_NON)
)],
// containsQrIban, paymentReferenceType
[true, PaymentReference::TYPE_QR,],
[false, PaymentReference::TYPE_SCOR,],
[false, PaymentReference::TYPE_NON,],
];
}

/**
* @dataProvider invalidCombinationsQrBillMocksProvider
*/
public function testInvalidCombinations(QrBill $qrBillMock)
#[DataProvider('invalidCombinationsQrBillMocksProvider')]
public function testInvalidCombinations(bool $containsQrIban, string $paymentReferenceType)
{
$qrBillMock = $this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', $containsQrIban),
$this->getPaymentReferenceMock($paymentReferenceType)
);

$this->validator->validate($qrBillMock, new ValidCreditorInformationPaymentReferenceCombination([
'message' => 'myMessage',
]));
Expand All @@ -102,21 +96,13 @@ public function testInvalidCombinations(QrBill $qrBillMock)
->assertRaised();
}

public function invalidCombinationsQrBillMocksProvider(): array
public static function invalidCombinationsQrBillMocksProvider(): array
{
return [
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', false),
$this->getPaymentReferenceMock(PaymentReference::TYPE_QR)
)],
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', true),
$this->getPaymentReferenceMock(PaymentReference::TYPE_SCOR)
)],
[$this->getQrBillMock(
$this->getCreditorInformationMock('any-iban', true),
$this->getPaymentReferenceMock(PaymentReference::TYPE_NON)
)],
// containsQrIban, paymentReferenceType
[false, PaymentReference::TYPE_QR,],
[true, PaymentReference::TYPE_SCOR,],
[true, PaymentReference::TYPE_NON,],
];
}

Expand Down
13 changes: 5 additions & 8 deletions tests/Constraints/ValidCreditorReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sprain\Tests\SwissQrBill\Constraints;

use PHPUnit\Framework\Attributes\DataProvider;
use Sprain\SwissQrBill\Constraint\ValidCreditorReference;
use Sprain\SwissQrBill\Constraint\ValidCreditorReferenceValidator;
use Symfony\Component\Validator\ConstraintValidatorInterface;
Expand All @@ -28,27 +29,23 @@ public function testEmptyStringIsValid()
$this->assertNoViolation();
}

/**
* @dataProvider getValidCreditorReferences
*/
#[DataProvider('getValidCreditorReferences')]
public function testValidCreditorReferences($value)
{
$this->validator->validate($value, new ValidCreditorReference());

$this->assertNoViolation();
}

public function getValidCreditorReferences()
public static function getValidCreditorReferences()
{
return [
['RF45 1234 5123 45'],
['RF451234512345']
];
}

/**
* @dataProvider getInvalidCreditorReferences
*/
#[DataProvider('getInvalidCreditorReferences')]
public function testInvalidCreditorReferences($creditorReference)
{
$this->validator->validate($creditorReference, new ValidCreditorReference([
Expand All @@ -60,7 +57,7 @@ public function testInvalidCreditorReferences($creditorReference)
->assertRaised();
}

public function getInvalidCreditorReferences()
public static function getInvalidCreditorReferences()
{
return [
['RF43 1234 5123 45'],
Expand Down
13 changes: 5 additions & 8 deletions tests/DataGroup/Element/AdditionalInformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Sprain\Tests\SwissQrBill\DataGroup\Element;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Sprain\SwissQrBill\DataGroup\Element\AdditionalInformation;

final class AdditionalInformationTest extends TestCase
{
/**
* @dataProvider messageProvider
*/
#[DataProvider('messageProvider')]
public function testMessage(int $numberOfValidations, ?string $value): void
{
$additionalInformation = AdditionalInformation::create($value);

$this->assertSame($numberOfValidations, $additionalInformation->getViolations()->count());
}

public function messageProvider(): array
public static function messageProvider(): array
{
return [
[0, '012345678901234567890123456'],
Expand All @@ -27,17 +26,15 @@ public function messageProvider(): array
];
}

/**
* @dataProvider billInformationProvider
*/
#[DataProvider('billInformationProvider')]
public function testBillInformation(int $numberOfValidations, ?string $value)
{
$additionalInformation = AdditionalInformation::create(null, $value);

$this->assertSame($numberOfValidations, $additionalInformation->getViolations()->count());
}

public function billInformationProvider(): array
public static function billInformationProvider(): array
{
return [
[0, '012345678901234567890123456'],
Expand Down
7 changes: 3 additions & 4 deletions tests/DataGroup/Element/AlternativeSchemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace Sprain\Tests\SwissQrBill\DataGroup\Element;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Sprain\SwissQrBill\DataGroup\Element\AlternativeScheme;

final class AlternativeSchemeTest extends TestCase
{
/**
* @dataProvider parameterProvider
*/
#[DataProvider('parameterProvider')]
public function testParameter(int $numberOfValidations, string $value): void
{
$alternativeScheme = AlternativeScheme::create($value);

$this->assertSame($numberOfValidations, $alternativeScheme->getViolations()->count());
}

public function parameterProvider(): array
public static function parameterProvider(): array
{
return [
[0, '1'],
Expand Down
Loading