Skip to content

Commit

Permalink
Merge pull request #15 from bjd-php/fix-deprecations
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
J-Ben87 authored Sep 4, 2019
2 parents 201fee8 + 8f45d69 commit 05fb51d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 34 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ language: php
php:
- 7.1
- 7.2
- 7.3

env:
- SYMFONY_VERSION=4.0.*
- SYMFONY_VERSION=4.2.*
- SYMFONY_VERSION=4.3.*

sudo: false

Expand Down
6 changes: 4 additions & 2 deletions Constraint/Factory/FactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JBen87\ParsleyBundle\Constraint\Factory;

use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

trait FactoryTrait
{
Expand Down Expand Up @@ -54,6 +54,8 @@ private function transChoice(
string $domain = 'validators',
string $locale = null
): string {
return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
$parameters['%count%'] = $number;

return $this->translator->trans($id, $parameters, $domain, $locale);
}
}
2 changes: 1 addition & 1 deletion Constraint/Factory/TranslatableFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JBen87\ParsleyBundle\Constraint\Factory;

use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

interface TranslatableFactoryInterface extends FactoryInterface
{
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct(string $alias)
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$treeBuilder = new TreeBuilder($this->alias);

$rootNode = $treeBuilder->root($this->alias);
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->booleanNode('enabled')
Expand Down
4 changes: 2 additions & 2 deletions Form/Extension/ParsleyTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public function configureOptions(OptionsResolver $resolver): void
/**
* @inheritdoc
*/
public function getExtendedType(): string
public static function getExtendedTypes(): iterable
{
return FormType::class;
yield FormType::class;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Constraint/Factory/FactoryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use JBen87\ParsleyBundle\Constraint\Factory\TranslatableFactoryInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraint as SymfonyConstraint;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class FactoryTestCase extends TestCase
{
Expand Down
28 changes: 13 additions & 15 deletions Tests/Constraint/Factory/LengthFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,22 @@ function (LengthFactoryTest $self): void {
]),
function (LengthFactoryTest $self): void {
$self->translator
->expects($this->once())
->expects($this->exactly(2))
->method('trans')
->with(
static::ORIGINAL_MESSAGE,
['{{ min }}' => static::LIMIT, '{{ max }}' => static::LIMIT]
->withConsecutive(
[
static::ORIGINAL_MESSAGE,
['{{ min }}' => static::LIMIT, '{{ max }}' => static::LIMIT],
],
[
static::ORIGINAL_EXACT_MESSAGE,
['{{ limit }}' => static::LIMIT, '%count%' => static::LIMIT],
]
)
->willReturn(sprintf('This value should have %d to %d characters.', static::MAX, static::MIN))
;

$self->translator
->expects($this->once())
->method('transChoice')
->with(
static::ORIGINAL_EXACT_MESSAGE,
static::LIMIT,
['{{ limit }}' => static::LIMIT]
->willReturnOnConsecutiveCalls(
sprintf('This value should have %d to %d characters.', static::MAX, static::MIN),
static::TRANSLATED_EXACT_MESSAGE
)
->willReturn(static::TRANSLATED_EXACT_MESSAGE)
;
},
],
Expand Down
7 changes: 5 additions & 2 deletions Tests/Constraint/Factory/MaxLengthFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ protected function setUpCreate(): void
{
$this->translator
->expects($this->once())
->method('transChoice')
->with(static::ORIGINAL_MESSAGE, static::LIMIT, ['{{ limit }}' => static::LIMIT])
->method('trans')
->with(
static::ORIGINAL_MESSAGE,
['{{ limit }}' => static::LIMIT, '%count%' => static::LIMIT]
)
->willReturn(static::TRANSLATED_MESSAGE)
;
}
Expand Down
7 changes: 5 additions & 2 deletions Tests/Constraint/Factory/MinLengthFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ protected function setUpCreate(): void
{
$this->translator
->expects($this->once())
->method('transChoice')
->with(static::ORIGINAL_MESSAGE, static::LIMIT, ['{{ limit }}' => static::LIMIT])
->method('trans')
->with(
static::ORIGINAL_MESSAGE,
['{{ limit }}' => static::LIMIT, '%count%' => static::LIMIT]
)
->willReturn(static::TRANSLATED_MESSAGE)
;
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Form/Extension/ParsleyTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function testConfiguration(): void
$extension = $this->createExtension();
$options = $this->resolveExtensionOptions($extension, []);

$this->assertSame(FormType::class, $extension->getExtendedType());
$this->assertCount(1, ParsleyTypeExtension::getExtendedTypes());
$this->assertContains(FormType::class, ParsleyTypeExtension::getExtendedTypes());
$this->assertTrue($options['parsley_enabled']);
$this->assertSame('blur', $options['parsley_trigger_event']);
}
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
"require": {
"php": ">=7.1",
"monolog/monolog": "^1.23",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/serializer": "^4.0",
"symfony/validator": "^4.0"
"symfony/form": "^4.2",
"symfony/framework-bundle": "^4.2",
"symfony/serializer": "^4.2",
"symfony/validator": "^4.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"phpunit/phpunit": "^7.1",
"squizlabs/php_codesniffer": "^3.2"
"phpstan/phpstan": "^0.11.15"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 05fb51d

Please sign in to comment.