Skip to content

Commit

Permalink
BESTSELLER-7094 SF 6.x Update dependencies to support SF6
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaskioglu-valiton committed Jul 4, 2024
1 parent cea2f9a commit ffaba5c
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 121 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"symfony/finder": "^4.0 || ^5.0 || ^6.0",
"symfony/options-resolver": "^4.0 || ^5.0 || ^6.0",
"symfony/translation": "^4.0 || ^5.0 || ^6.0",
"symfony/yaml": "^4.0 || ^5.0 || ^6.0"
"symfony/yaml": "^4.0 || ^5.0 || ^6.0",
"symfony/cache": "^4.0 || ^5.0 || ^6.4"
},
"require-dev": {
"symfony/intl": "^4.0 || ^5.0 || ^6.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Translator/TranslatorBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setHandler(BaseTranslatorInterface $handler)
/**
* {@inheritdoc}
*/
public function trans($id, array $parameters = [], $domain = null, $locale = null)
public function trans($id, array $parameters = [], $domain = null, $locale = null): string
{
$tranlation = $this->getHandler()->trans($id, $parameters, $domain, $locale);

Expand Down Expand Up @@ -82,7 +82,7 @@ public function setLocale($locale)
/**
* {@inheritdoc}
*/
public function getLocale()
public function getLocale(): string
{
$locale = $this->getHandler()->getLocale();

Expand Down
3 changes: 2 additions & 1 deletion src/Validator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function __construct(Configuration $configuration, TranslatorInterface $t
}

$builder = BaseValidation::createValidatorBuilder();
$builder->enableAnnotationMapping();
$builder->enableAttributeMapping()
->addDefaultDoctrineAnnotationReader();
$builder->addMethodMapping('loadValidatorMetadata');
if (!is_null($translator)) {
$builder->setTranslator($translator);
Expand Down
188 changes: 95 additions & 93 deletions tests/FormWithValidatorBridgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Naucon\Form\Tests;

use Naucon\Form\Form;
Expand All @@ -21,105 +22,105 @@ class FormWithValidatorBridgeTest extends TestCase
{
public function entityProvider()
{
return array(
array(
return [
[
new UserWithConfig(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'username' => 'max.mustermann',
'firstname' => 'Max',
'lastname' => 'Mustermann',
'email' => '[email protected]',
'age' => '18'
),
],
true,
true,
array(),
[],
'valid dataset user form'
),
array(
],
[
new UserWithConfig(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'username' => '',
'firstname' => 'Max',
'lastname' => 'Mustermann',
'email' => '[email protected]',
'age' => 'monday'
),
],
true,
false,
array('username', 'age'),
['username', 'age'],
'invalid dataset user form with missing username and wrong age type'
),
array(
],
[
new UserWithConfig(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'email' => '[email protected]',
),
],
true,
false,
array('username'),
['username'],
'invalid dataset user form with missing username'
),
array(
],
[
new UserWithConfig(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(),
],
[],
false,
false,
array('username'),
['username'],
'invalid dataset user form with missing form data'
)
);
]
];
}

/**
* @dataProvider entityProvider
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
*/
public function testFormBindWithYmlValidator($entity, $config, $methods, $dataMap, $expectedIsBound, $expectedIsValid, $expectedErrors)
{
foreach ($methods as $method) {
$this->assertEquals('', $entity->$method());
}

$configPaths = array(__DIR__ . '/Resources/config/yml/validation.yml');
$configPaths = [__DIR__ . '/Resources/config/yml/validation.yml'];

$handler = Validation::createValidatorBuilder()
->addYamlMappings($configPaths)
Expand All @@ -132,7 +133,7 @@ public function testFormBindWithYmlValidator($entity, $config, $methods, $dataMa
$form = new Form($entity, 'testform', $configuration);
$form->setValidator($validatorBridge);

$payload = array();
$payload = [];
$payload['_csrf_token'] = $form->getSynchronizerToken();
if (count($dataMap)) {
$payload['testform'] = $dataMap;
Expand Down Expand Up @@ -162,21 +163,21 @@ public function testFormBindWithYmlValidator($entity, $config, $methods, $dataMa

/**
* @dataProvider entityProvider
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
*/
public function testFormBindWithXmlValidator($entity, $config, $methods, $dataMap, $expectedIsBound, $expectedIsValid, $expectedErrors)
{
foreach ($methods as $method) {
$this->assertEquals('', $entity->$method());
}

$configPaths = array(__DIR__ . '/Resources/config/xml/validation.xml');
$configPaths = [__DIR__ . '/Resources/config/xml/validation.xml'];

$handler = Validation::createValidatorBuilder()
->addXmlMappings($configPaths)
Expand All @@ -189,7 +190,7 @@ public function testFormBindWithXmlValidator($entity, $config, $methods, $dataMa
$form = new Form($entity, 'testform', $configuration);
$form->setValidator($validatorBridge);

$payload = array();
$payload = [];
$payload['_csrf_token'] = $form->getSynchronizerToken();
if (count($dataMap)) {
$payload['testform'] = $dataMap;
Expand Down Expand Up @@ -219,97 +220,97 @@ public function testFormBindWithXmlValidator($entity, $config, $methods, $dataMa

public function entityProviderWithAnnotation()
{
return array(
array(
return [
[
new UserWithAnnotation(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'username' => 'max.mustermann',
'firstname' => 'Max',
'lastname' => 'Mustermann',
'email' => '[email protected]',
'age' => '18'
),
],
true,
true,
array(),
[],
'valid dataset user form'
),
array(
],
[
new UserWithAnnotation(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'username' => '',
'firstname' => 'Max',
'lastname' => 'Mustermann',
'email' => '[email protected]',
'age' => 'monday'
),
],
true,
false,
array('username', 'age'),
['username', 'age'],
'invalid dataset user form with missing username and wrong age type'
),
array(
],
[
new UserWithAnnotation(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(
],
[
'email' => '[email protected]',
),
],
true,
false,
array('username'),
['username'],
'invalid dataset user form with missing username'
),
array(
],
[
new UserWithAnnotation(),
array(),
array(
[],
[
'username' => 'getUsername',
'firstname' => 'getFirstname',
'lastname' => 'getLastname',
'email' => 'getEmail',
'age' => 'getAge'
),
array(),
],
[],
false,
false,
array('username'),
['username'],
'invalid dataset user form with missing form data'
)
);
]
];
}

/**
* @dataProvider entityProviderWithAnnotation
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
* @param object $entity entity a plain old php object
* @param array $config form configuration
* @param array $methods array of getters for the entity
* @param array $dataMap form data
* @param bool $expectedIsBound expected form bind result
* @param bool $expectedIsValid expected form validation result
* @param array $expectedErrors expected form validation errors
*/
public function testFormBindWithAnnotationValidator($entity, $config, $methods, $dataMap, $expectedIsBound, $expectedIsValid, $expectedErrors)
{
Expand All @@ -318,7 +319,8 @@ public function testFormBindWithAnnotationValidator($entity, $config, $methods,
}

$handler = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->enableAttributeMapping()
->addDefaultDoctrineAnnotationReader()
->getValidator();

$validatorBridge = new ValidatorBridge($handler);
Expand All @@ -328,7 +330,7 @@ public function testFormBindWithAnnotationValidator($entity, $config, $methods,
$form = new Form($entity, 'testform', $configuration);
$form->setValidator($validatorBridge);

$payload = array();
$payload = [];
$payload['_csrf_token'] = $form->getSynchronizerToken();
if (count($dataMap)) {
$payload['testform'] = $dataMap;
Expand Down
Loading

0 comments on commit ffaba5c

Please sign in to comment.