Skip to content

Commit

Permalink
Merge pull request #158 from jmsche/allow-symfony-7
Browse files Browse the repository at this point in the history
Allow Symfony 7 & drop support for unmaintained Symfony versions
  • Loading branch information
odolbeau authored Nov 29, 2023
2 parents c3237ff + 2674f3a commit 60c8166
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: PHPStan
uses: docker://jakzal/phpqa:php8.0
uses: docker://jakzal/phpqa:php8.2
with:
args: phpstan analyze --no-progress

Expand All @@ -17,6 +17,6 @@ jobs:
steps:
- uses: actions/checkout@master
- name: PHP-CS-Fixer
uses: docker://jakzal/phpqa:php8.0
uses: docker://jakzal/phpqa:php8.2
with:
args: php-cs-fixer fix --config=.php_cs.dist.php --dry-run --diff
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ jobs:
strategy:
matrix:
include:
- php: '7.4'
symfony-require: 4.4.*
- php: '8.0'
symfony-require: 5.3.*
symfony-require: 5.4.*
- php: '8.0'
symfony-require: 6.0.*
symfony-require: 6.3.*
- php: '8.2'
symfony-require: 7.0.*
stability: dev
- php: '8.1'
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Remove support of Symfony 4.x, 5.3 & < 6.3
- Add support for Symfony 7

## [3.9.3] - 2023-11-29

### Added
Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"require": {
"php": ">=7.4",
"giggsey/libphonenumber-for-php": "^8.0",
"symfony/framework-bundle": "^4.4|^5.3|^6.0",
"symfony/intl": "^4.4|^5.3|^6.0",
"symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0",
"symfony/intl": "^5.4 || ^6.3 || ^7.0",
"symfony/polyfill-mbstring": "^1.28"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.12|^2.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"symfony/form": "^4.4|^5.3|^6.0",
"symfony/phpunit-bridge": "^6.2",
"symfony/property-access": "^4.4|^5.3|^6.0",
"symfony/serializer": "^4.4|^5.3|^6.0.1",
"symfony/twig-bundle": "^4.4|^5.3|^6.0",
"symfony/validator": "^4.4|^5.3|^6.0"
"symfony/form": "^5.4 || ^6.3 || ^7.0",
"symfony/phpunit-bridge": "^6.3 || ^7.0",
"symfony/property-access": "^5.4 || ^6.3 || ^7.0",
"symfony/serializer": "^5.4 || ^6.3 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.3 || ^7.0",
"symfony/validator": "^5.4 || ^6.3 || ^7.0"
},
"suggest": {
"doctrine/doctrine-bundle": "Add a DBAL mapping type",
Expand All @@ -54,8 +54,5 @@
"branch-alias": {
"dev-master": "3.9.x-dev"
}
},
"conflict": {
"symfony/serializer": "6.0.0"
}
}
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ parameters:
- src
- tests
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
-
message: "#^Attribute class Symfony\\\\Component\\\\Validator\\\\Attribute\\\\HasNamedArguments does not exist\\.$#"
count: 1
path: src/Validator/Constraints/PhoneNumber.php
18 changes: 16 additions & 2 deletions src/Doctrine/DBAL/Types/PhoneNumberType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Exception\InvalidType;
use Doctrine\DBAL\Types\Type;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumber;
Expand All @@ -36,7 +37,13 @@ public function getName(): string

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return $platform->getVarcharTypeDeclarationSQL(['length' => $fieldDeclaration['length'] ?? 35]);
// DBAL < 4
if (method_exists(AbstractPlatform::class, 'getVarcharTypeDeclarationSQL')) {
return $platform->getVarcharTypeDeclarationSQL(['length' => $fieldDeclaration['length'] ?? 35]);
}

// DBAL 4
return $platform->getStringTypeDeclarationSQL(['length' => $fieldDeclaration['length'] ?? 35]);
}

public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
Expand Down Expand Up @@ -65,7 +72,14 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?PhoneNum
try {
return $util->parse($value, PhoneNumberUtil::UNKNOWN_REGION);
} catch (NumberParseException $e) {
throw ConversionException::conversionFailed($value, self::NAME);
if (method_exists(ConversionException::class, 'conversionFailed')) {
// DBAL < 4
throw ConversionException::conversionFailed($value, self::NAME);
}

// DBAL 4
// @phpstan-ignore-next-line
throw InvalidType::new($value, self::NAME, ['null', 'string']);
}
}

Expand Down
16 changes: 14 additions & 2 deletions tests/Doctrine/DBAL/Types/PhoneNumberTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public static function setUpBeforeClass(): void
protected function setUp(): void
{
$this->platform = $this->prophesize(AbstractPlatform::class);
$this->platform->getVarcharTypeDeclarationSQL()->willReturn('DUMMYVARCHAR()');
if (method_exists(AbstractPlatform::class, 'getVarcharTypeDeclarationSQL')) {
// DBAL < 4
$this->platform->getVarcharTypeDeclarationSQL()->willReturn('DUMMYVARCHAR()');
} else {
// DBAL 4
$this->platform->getStringTypeDeclarationSQL()->willReturn('DUMMYVARCHAR()');
}

$this->type = Type::getType('phone_number');
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
Expand All @@ -68,7 +74,13 @@ public function testGetName()

public function testGetSQLDeclaration()
{
$this->platform->getVarcharTypeDeclarationSQL(['length' => 35])->willReturn('DUMMYVARCHAR()');
if (method_exists(AbstractPlatform::class, 'getVarcharTypeDeclarationSQL')) {
// DBAL < 4
$this->platform->getVarcharTypeDeclarationSQL(['length' => 35])->willReturn('DUMMYVARCHAR()');
} else {
// DBAL 4
$this->platform->getStringTypeDeclarationSQL(['length' => 35])->willReturn('DUMMYVARCHAR()');
}
$this->assertSame('DUMMYVARCHAR()', $this->type->getSQLDeclaration([], $this->platform->reveal()));
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Validator/Constraints/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function testProperties()
{
$phoneNumber = new PhoneNumber();

$this->assertObjectHasAttribute('message', $phoneNumber);
$this->assertObjectHasAttribute('type', $phoneNumber);
$this->assertObjectHasAttribute('defaultRegion', $phoneNumber);
$this->assertObjectHasAttribute('regionPath', $phoneNumber);
$this->assertObjectHasProperty('message', $phoneNumber);
$this->assertObjectHasProperty('type', $phoneNumber);
$this->assertObjectHasProperty('defaultRegion', $phoneNumber);
$this->assertObjectHasProperty('regionPath', $phoneNumber);
}

/**
Expand Down
10 changes: 6 additions & 4 deletions tests/Validator/Constraints/PhoneNumberValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Validator\Mapping\Loader\AttributeLoader;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;

/**
Expand Down Expand Up @@ -67,9 +68,6 @@ public function testValidate($value, $violates, $type = null, $defaultRegion = n
->method('setCode')
->with($this->isType('string'))
->willReturn($constraintViolationBuilder);
$constraintViolationBuilder
->method('addViolation')
->willReturn($constraintViolationBuilder);

$this->context
->expects($this->once())
Expand All @@ -89,7 +87,11 @@ public function testValidate($value, $violates, $type = null, $defaultRegion = n
public function testValidateFromAttribute()
{
$classMetadata = new ClassMetadata(PhoneNumberDummy::class);
(new AnnotationLoader())->loadClassMetadata($classMetadata);
if (class_exists(AnnotationLoader::class)) {
(new AnnotationLoader())->loadClassMetadata($classMetadata);
} else {
(new AttributeLoader())->loadClassMetadata($classMetadata);
}

[$constraint1] = $classMetadata->properties['phoneNumber1']->constraints;
[$constraint2] = $classMetadata->properties['phoneNumber2']->constraints;
Expand Down

0 comments on commit 60c8166

Please sign in to comment.