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

Drop PHP 8.0 support #58

Merged
merged 2 commits into from
Apr 29, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
php-version: [ 8.1 ]
php-version: [ 8.3 ]
composer: [ highest ]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3

- uses: "ramsey/composer-install@v3"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sast.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.3

- uses: "ramsey/composer-install@v3"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.0', 8.1, 8.2, 8.3]
php-version: [8.1, 8.2, 8.3]
composer: [highest, lowest]

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/logs/
/.php-cs-fixer.cache
/.phpunit.result.cache
/infection.txt
/.phpunit.cache
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[
'@PSR2' => true,
'@PSR12' => true,
'@PHP80Migration' => true,
'@PHP81Migration' => true,
'single_quote' => true,
]
)->setFinder($finder);
4 changes: 2 additions & 2 deletions build/BuildMetadataFromXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public static function validateRE(string $regex, bool $removeWhitespace = false)
{
$compressedRegex = $removeWhitespace ? \preg_replace('/\\s/', '', $regex) : $regex;
// Match regex against an empty string to check the regex is valid
if (\preg_match('/' . $compressedRegex . '/', '') === false) {
throw new \RuntimeException('Regex error: ' . \preg_last_error());
if (@preg_match('/' . $compressedRegex . '/', '') === false) {
throw new \RuntimeException('Regex error: ' . \preg_last_error_msg());
}
// We don't ever expect to see | followed by a ) in our metadata - this would be an indication
// of a bug. If one wants to make something optional, we prefer ? to using an empty group.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@
]
},
"require": {
"php": "^8.0",
"php": "^8.1",
"symfony/polyfill-mbstring": "^1.17"
},
"require-dev": {
"ext-dom": "*",
"friendsofphp/php-cs-fixer": "^3.12",
"infection/infection": "^0.26.16",
"infection/infection": "^0.28",
"pear/pear-core-minimal": "^1.10.11",
"pear/pear_exception": "^1.0.2",
"pear/versioncontrol_git": "^0.5",
"pear/versioncontrol_git": "^0.7",
"phing/phing": "^2.17.4",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.2",
"phpunit/phpunit": "^9.5.26",
"phpunit/phpunit": "^10.5",
"symfony/console": "^6.0"
},
"conflict": {
Expand Down
34 changes: 23 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="./tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
convertDeprecationsToExceptions="true"
executionOrder="random"
colors="true">
<coverage>
colors="true"
failOnRisky="true"
failOnWarning="true"
failOnDeprecation="true"
failOnEmptyTestSuite="true"
failOnIncomplete="true"
failOnNotice="true"
failOnSkipped="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit Tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">./build/</directory>
Expand All @@ -20,10 +37,5 @@
<file>./src/CountryCodeToRegionCodeMap.php</file>
<file>./src/CountryCodeToRegionCodeMapForTesting.php</file>
</exclude>
</coverage>
<testsuites>
<testsuite name="Unit Tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</source>
</phpunit>
7 changes: 3 additions & 4 deletions tests/Issues/PHP7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class PHP7Test extends TestCase
Expand All @@ -16,9 +17,7 @@ public function setUp(): void
$this->phoneUtil = PhoneNumberUtil::getInstance();
}

/**
* @dataProvider validPolishNumbers
*/
#[DataProvider('validPolishNumbers')]
public function testValidPolishNumbers(string $number): void
{
$phoneNumber = $this->phoneUtil->parse($number, 'PL');
Expand All @@ -30,7 +29,7 @@ public function testValidPolishNumbers(string $number): void
/**
* @return array<string[]>
*/
public function validPolishNumbers(): array
public static function validPolishNumbers(): array
{
return [
['22 222 22 22'],
Expand Down
48 changes: 17 additions & 31 deletions tests/buildtools/BuildMetadataFromXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use libphonenumber\NumberFormat;
use libphonenumber\PhoneMetadata;
use libphonenumber\PhoneNumberDesc;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

class BuildMetadataFromXmlTest extends TestCase
Expand All @@ -25,46 +27,30 @@ public function testValidateRERemovesWhiteSpaces(): void
$this->assertEquals(' hello world ', BuildMetadataFromXml::validateRE($input, false));
}

public function testValidateREThrowsException(): void
#[TestWith([false])]
#[TestWith([true])]
public function testValidateREThrowsException(bool $removeWhitespace): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Regex error: Internal error');

$invalidPattern = '[';
// Should throw an exception when an invalid pattern is provided independently of the last
// parameter (remove white spaces).
try {
BuildMetadataFromXml::validateRE($invalidPattern, false);
$this->fail();
} catch (\Exception $e) {
// Test passed.
$this->addToAssertionCount(1);
}
BuildMetadataFromXml::validateRE($invalidPattern, $removeWhitespace);
}

try {
BuildMetadataFromXml::validateRE($invalidPattern, true);
$this->fail();
} catch (\Exception $e) {
// Test passed.
$this->addToAssertionCount(1);
}
#[TestWith(['|)'])]
#[TestWith(["|\n)"])]
public function testValidateREThrowsExceptionWithPatterns(string $pattern): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Regex error: Internal error');

// We don't allow | to be followed by ) because it introduces bugs, since we typically use it at
// the end of each line and when a line is deleted, if the pipe from the previous line is not
// removed, we end up erroneously accepting an empty group as well.
$patternWithPipeFollowedByClosingParentheses = '|)';
try {
BuildMetadataFromXml::validateRE($patternWithPipeFollowedByClosingParentheses, true);
$this->fail();
} catch (\Exception $e) {
// Test passed.
$this->addToAssertionCount(1);
}
$patternWithPipeFollowedByNewLineAndClosingParentheses = "|\n)";
try {
BuildMetadataFromXml::validateRE($patternWithPipeFollowedByNewLineAndClosingParentheses, true);
$this->fail();
} catch (\Exception $e) {
// Test passed.
$this->addToAssertionCount(1);
}
BuildMetadataFromXml::validateRE($pattern, true);
}

public function testValidateRE(): void
Expand Down
Loading
Loading