Skip to content

Commit

Permalink
Allow Symfony 7 (#25)
Browse files Browse the repository at this point in the history
* Add return type declarations

* Adapt test config and attributes for Symfony 7
  • Loading branch information
Lustmored committed Jan 19, 2024
1 parent 6097dc0 commit 6fa732b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^8.5 || ^9.0",
"doctrine/annotations": "^1.2",
"symfony/framework-bundle": "^5.0 || ^6.0",
"symfony/yaml": "^5.0 || ^6.0"
"symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^5.0 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/DdeboerVatinExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DdeboerVatinExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/Constraints/VatinValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(Validator $validator)
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
public function validate($value, Constraint $constraint): void
{
if (null === $value || '' === $value) {
return;
Expand All @@ -56,7 +56,7 @@ public function validate($value, Constraint $constraint)
*
* @return bool
*/
private function isValidVatin($value, $checkExistence)
private function isValidVatin($value, $checkExistence): bool
{
try {
return $this->validator->isValid($value, $checkExistence);
Expand Down
2 changes: 2 additions & 0 deletions tests/Functional/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class Model
/**
* @Vatin
*/
#[Vatin]
public $vat;

/**
* @Vatin(checkExistence=true)
*/
#[Vatin(checkExistence: true)]
public $vatCheckExistence;
}
6 changes: 5 additions & 1 deletion tests/Functional/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public function registerBundles(): iterable

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config.yml');
if (self::MAJOR_VERSION >= 7) {
$loader->load(__DIR__ . '/config/config_7.yml');
} else {
$loader->load(__DIR__ . '/config/config.yml');
}
}
}
10 changes: 10 additions & 0 deletions tests/Functional/app/config/config_7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
framework:
secret: ddeboer
test: ~
validation:
enable_attributes: true

services:
test.validator:
alias: validator
public: true
3 changes: 2 additions & 1 deletion tests/Validator/Constraints/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Ddeboer\Vatin\Validator;
use Ddeboer\VatinBundle\Validator\Constraints\Vatin;
use Ddeboer\VatinBundle\Validator\Constraints\VatinValidator;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;

class ValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
protected function createValidator(): ConstraintValidatorInterface
{
return new VatinValidator(new Validator());
}
Expand Down

0 comments on commit 6fa732b

Please sign in to comment.