diff --git a/.editorconfig b/.editorconfig index 532f629..c9a2a17 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,11 +8,11 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.yaml] +[*.{json,yaml,yml}] indent_size = 2 -[*.neon] -indent_style = tab - [*.md] trim_trailing_whitespace = false + +[*.neon] +indent_style = tab diff --git a/.gitattributes b/.gitattributes index 5c9c0cb..9c57bf0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,11 +1,12 @@ -/.github/ export-ignore -/bin/ export-ignore -/docs/ export-ignore -/tests/ export-ignore /.editorconfig export-ignore /.gitattributes export-ignore +/.github/ export-ignore /.gitignore export-ignore /.php-cs-fixer.php export-ignore +/bin/ export-ignore +/compose.yaml export-ignore /depfile.yaml export-ignore +/docs/ export-ignore /phpstan.neon export-ignore /phpunit.xml.dist export-ignore +/tests/ export-ignore diff --git a/.github/workflows/test-and-qa.yaml b/.github/workflows/test-and-qa.yaml index bb294bb..0b336af 100644 --- a/.github/workflows/test-and-qa.yaml +++ b/.github/workflows/test-and-qa.yaml @@ -5,6 +5,7 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + workflow_dispatch: permissions: contents: read diff --git a/.gitignore b/.gitignore index a10d0de..4296a36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,14 @@ -/.idea/ - -/vendor/ +# Composer /composer.lock +/vendor/ +# PHP-CS-Fixer /.php-cs-fixer.cache +# PHPUnit +/.phpunit.result.cache /.phpunit.cache/ -/phpunit.xml +/reports/ + +# IDE project files +/.idea/ diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2bf7f3c..4795d19 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,28 +1,39 @@ in([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->exclude([ - 'var/', - ]); -return $config +return (new PhpCsFixer\Config) + ->setFinder((new PhpCsFixer\Finder) + ->in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->notPath(['DependencyInjection/Configuration.php', 'app/var']) + ) ->setRiskyAllowed(true) ->setRules([ - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'blank_line_after_opening_tag' => true, - 'concat_space' => ['spacing' => 'one'], - 'declare_strict_types' => true, - 'linebreak_after_opening_tag' => true, - ]) - ->setFinder($finder); + '@Symfony' => true, + '@Symfony:risky' => true, + + // declare strict types must be on first line after opening tag + 'blank_line_after_opening_tag' => false, // overwrite @Symfony + 'linebreak_after_opening_tag' => false, // overwrite @Symfony + 'declare_strict_types' => true, // custom + + // allow throw's in multiple lines, so message can be a long string + 'single_line_throw' => false, // overwrite @Symfony + + // we want spaces + 'concat_space' => ['spacing' => 'one'], // overwrite @Symfony + + // we want to leave the choice to the developer, + // because some people have their own style of naming test methods + 'php_unit_method_casing' => false, // overwrite @Symfony + + // we want to leave the choice to the developer + 'php_unit_test_annotation' => false, // overwrite @Symfony:risky + ]); diff --git a/README.md b/README.md index 2e809c5..cb82a18 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,43 @@ A default implementation of the Converter & Populator design pattern. ## Installation -Run `composer require teamneusta/converter-bundle` to install the bundle. +1. **Require the bundle** -Add the following line into your `bundles.php` file to activate it: + ```shell + composer require teamneusta/converter-bundle + ``` -```php -... -return [ - ... - Neusta\ConverterBundle\NeustaConverterBundle::class => ['all' => true], - ... -]; -``` +2. **Enable the bundle** + + Add the Bundle to your `config/bundles.php`: + + ```php + Neusta\ConverterBundle\NeustaConverterBundle::class => ['all' => true], + ``` -This is important for preloading the default configuration of provided converter implementations which can be reused -and simplify your code and further updates. + This is important for preloading the default configuration of provided converter implementations which can be reused + and simplify your code and further updates. ## [Usage](docs/usage.md) -## [Development](docs/development.md) +## Contribution + +Feel free to open issues for any bug, feature request, or other ideas. + +Please remember to create an issue before creating large pull requests. + +### Local Development + +To develop on local machine, the vendor dependencies are required. + +```shell +bin/composer install +``` + +We use composer scripts for our main quality tools. They can be executed via the `bin/composer` file as well. + +```shell +bin/composer cs:fix +bin/composer phpstan +bin/composer tests +``` diff --git a/bin/composer b/bin/composer new file mode 100755 index 0000000..8f3aff6 --- /dev/null +++ b/bin/composer @@ -0,0 +1,3 @@ +#!/bin/sh + +exec docker compose run --rm --user "$(id -u):$(id -g)" --no-deps php composer "$@" diff --git a/bin/run-tests b/bin/run-tests new file mode 100755 index 0000000..6370046 --- /dev/null +++ b/bin/run-tests @@ -0,0 +1,4 @@ +#!/bin/sh + +docker compose run --rm --user "$(id -u):$(id -g)" php composer tests +docker compose down diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..885aa9e --- /dev/null +++ b/compose.yaml @@ -0,0 +1,27 @@ +services: + database: + image: mariadb:10.11.4 + command: [ "mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci" ] + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: pimcore + MYSQL_PASSWORD: pimcore + MYSQL_USER: pimcore + tmpfs: + - /tmp/ + - /var/lib/mysql/ + healthcheck: + test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ] + interval: 5s + timeout: 10s + + php: + image: pimcore/pimcore:php8.2-latest + volumes: + - ./:/var/www/html/ + - /home/ldschaak/.cache/composer:/.cache/composer + environment: + MYSQL_SERVER_VERSION: mariadb-10.11.4 + depends_on: + database: + condition: service_healthy diff --git a/composer.json b/composer.json index d3a3000..1c2c970 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,12 @@ "role": "Developer" } ], + "config": { + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } + }, "require": { "php": "^8.0", "symfony/config": "^5.4 || ^6.2", @@ -39,13 +45,6 @@ "symfony/test-pack": "^1.0", "symfony/yaml": "^5.4 || ^6.2" }, - "config": { - "preferred-install": "dist", - "sort-packages": true, - "allow-plugins": { - "phpstan/extension-installer": true - } - }, "autoload": { "psr-4": { "Neusta\\ConverterBundle\\": "src/" @@ -60,18 +59,24 @@ ] }, "scripts": { - "cs:check": "php-cs-fixer fix -v --diff --dry-run", - "cs:fix": "php-cs-fixer fix -v --diff", - "phpstan": "phpstan analyse --level=${PHPSTAN_LEVEL:-8} -c phpstan.neon", + "cs:check": "@cs:fix --dry-run", + "cs:check:gitlab-ci": "php-cs-fixer fix --dry-run --ansi --verbose --diff --format=gitlab > php-cs-fixer.json", + "cs:fix": "php-cs-fixer fix --ansi --verbose --diff", + "phpstan": "phpstan analyse --ansi", + "phpstan:gitlab-ci": "phpstan analyse --ansi --no-interaction --no-progress --error-format=gitlab > phpstan-report.json", "tests": "phpunit", + "tests:coverage:gitlab-ci": "phpunit --colors=never --coverage-text --coverage-cobertura .coverage/cobertura.xml --log-junit .coverage/junit.xml", "deptrac:analyse": "deptrac --config-file=depfile.yaml", "deptrac:analyse:visual": "deptrac --formatter=graphviz-html --output=deptrac.analyse-result.html --config-file=depfile.yaml" }, "scripts-descriptions": { "cs:check": "Checks code style (but doesn't fix anything)", - "cs:fix": "Fixes code style", - "phpstan": "PHPstan - find bugs and lacks in your type safety", - "tests": "Phpunit - write tests before you implement. That helps.", + "cs:check:gitlab-ci": "Checks code style and redirects the output into a GitLab readable file", + "cs:fix": "Checks and fixes code style", + "phpstan": "Checks for code smells", + "phpstan:gitlab-ci": "Checks for code smells and redirects the output into a GitLab readable file", + "tests": "Run all phpunit tests", + "tests:coverage:gitlab-ci": "Run all phpunit tests and create coverage reports", "deptrac:analyse": "Analyse your dependencies and follow the pre-defined rules and layers", "deptrac:analyse:visual": "Visualize your dependencies and follow the pre-defined rules and layers" } diff --git a/config/services.yaml b/config/services.yaml index 0eb1f1f..355a49e 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,37 +1,37 @@ services: - _defaults: - autowire: false - autoconfigure: false + _defaults: + autowire: false + autoconfigure: false - ############################################################ - # Generic Converter - ############################################################ - neusta_converter.generic_converter: - abstract: true - class: Neusta\ConverterBundle\Converter\GenericConverter + ############################################################ + # Generic Converter + ############################################################ + neusta_converter.generic_converter: + abstract: true + class: Neusta\ConverterBundle\Converter\GenericConverter - ############################################################ - # Strategic Converter - ############################################################ - neusta_converter.strategic_converter: - abstract: true - class: Neusta\ConverterBundle\Converter\StrategicConverter + ############################################################ + # Strategic Converter + ############################################################ + neusta_converter.strategic_converter: + abstract: true + class: Neusta\ConverterBundle\Converter\StrategicConverter - ############################################################ - # Populators - ############################################################ - neusta_converter.property_mapping_populator: - abstract: true - class: Neusta\ConverterBundle\Populator\PropertyMappingPopulator + ############################################################ + # Populators + ############################################################ + neusta_converter.property_mapping_populator: + abstract: true + class: Neusta\ConverterBundle\Populator\PropertyMappingPopulator - neusta_converter.converting_populator: - abstract: true - class: Neusta\ConverterBundle\Populator\ConvertingPopulator + neusta_converter.converting_populator: + abstract: true + class: Neusta\ConverterBundle\Populator\ConvertingPopulator - neusta_converter.array_property_mapping_populator: - abstract: true - class: Neusta\ConverterBundle\Populator\ArrayPropertyMappingPopulator + neusta_converter.array_property_mapping_populator: + abstract: true + class: Neusta\ConverterBundle\Populator\ArrayPropertyMappingPopulator - neusta_converter.array_converting_populator: - abstract: true - class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator + neusta_converter.array_converting_populator: + abstract: true + class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator diff --git a/docs/development.md b/docs/development.md deleted file mode 100644 index 07b7914..0000000 --- a/docs/development.md +++ /dev/null @@ -1,11 +0,0 @@ -## Development - -### Running tests (incl. code coverage) - -If you want to run the tests (incl. code coverage) you can do so by configuring Phpstorm in the following way: -![phpstorm-settings.png](images/phpstorm-settings.png) - -You can see that we are using the image `pimcore/pimcore:php8.2-debug-latest` here. Of course this could be updated -after a while. -But with this image we can do code coverage by running all tests via phpunit.xml: -![img.png](images/phpstorm-run-configuration.png) diff --git a/docs/images/phpstorm-run-configuration.png b/docs/images/phpstorm-run-configuration.png deleted file mode 100644 index 09d8533..0000000 Binary files a/docs/images/phpstorm-run-configuration.png and /dev/null differ diff --git a/docs/images/phpstorm-settings.png b/docs/images/phpstorm-settings.png deleted file mode 100644 index a4400c4..0000000 Binary files a/docs/images/phpstorm-settings.png and /dev/null differ diff --git a/docs/usage.md b/docs/usage.md index 3a1b4f0..3e6b581 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -98,8 +98,8 @@ To put things together, register the factory and populator as services: ```yaml # config/services.yaml services: - YourNamespace\PersonFactory: ~ - YourNamespace\PersonNamePopulator: ~ + YourNamespace\PersonFactory: ~ + YourNamespace\PersonNamePopulator: ~ ``` And then declare the following converter in your package config: @@ -107,12 +107,12 @@ And then declare the following converter in your package config: ```yaml # config/packages/neusta_converter.yaml neusta_converter: - converter: - person.converter: - target_factory: YourNamespace\PersonFactory - populators: - - YourNamespace\PersonNamePopulator - # additional populators may follow + converter: + person.converter: + target_factory: YourNamespace\PersonFactory + populators: + - YourNamespace\PersonNamePopulator + # additional populators may follow ``` > Note: You can use a custom implementation of the `Converter` interface via the `converter` keyword. @@ -129,12 +129,12 @@ You can use it in your converter config via the `properties` keyword: ```yaml # config/packages/neusta_converter.yaml neusta_converter: - converter: - person.converter: - ... - properties: - email: ~ - phoneNumber: phone + converter: + person.converter: + # ... + properties: + email: ~ + phoneNumber: phone ``` Which will populate @@ -164,7 +164,7 @@ You can use it in your converter config via the `context` keyword: neusta_converter: converter: person.converter: - ... + # ... context: group: ~ locale: language @@ -251,22 +251,22 @@ Therefore, we have a `ConvertingPopulator` which can be used as follows: ```yaml # config/packages/neusta_converter.yaml neusta_converter: - converter: - person.converter: - ... - populators: - - person.address.populator + converter: + person.converter: + # ... + populators: + - person.address.populator - address.converter: - ... + address.converter: + # ... -... +# ... person.address.populator: - class: Neusta\ConverterBundle\Populator\ConvertingPopulator - arguments: - $converter: '@address.converter' - $sourcePropertyName: 'address' - $targetPropertyName: 'address' + class: Neusta\ConverterBundle\Populator\ConvertingPopulator + arguments: + $converter: '@address.converter' + $sourcePropertyName: 'address' + $targetPropertyName: 'address' ``` Be aware - that both properties have the same name should not lead you think they have the same type. @@ -323,22 +323,22 @@ Now you have to declare the following populator: ```yaml # config/packages/neusta_converter.yaml neusta_converter: - converter: - person.converter: - ... - populators: - - person.addresses.populator + converter: + person.converter: + # ... + populators: + - person.addresses.populator - address.converter: - ... + address.converter: + # ... -... +# ... person.addresses.populator: - class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator - arguments: - $converter: '@address.converter' - $sourcePropertyName: 'addresses' - $targetPropertyName: 'addresses' + class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator + arguments: + $converter: '@address.converter' + $sourcePropertyName: 'addresses' + $targetPropertyName: 'addresses' ``` There is no new converter but a different populator implementation for this. diff --git a/phpstan.neon b/phpstan.neon index e967f5b..393aff3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,9 @@ parameters: + + level: 8 + paths: - src -# - tests - - excludePaths: - - vendor - - tests/app symfony: containerXmlPath: tests/app/var/cache/test/TestKernelTestDebugContainer.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d5cfbbc..9e7d999 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,7 +3,8 @@ - + ./tests/ diff --git a/src/Converter.php b/src/Converter.php index 80f9767..c3750d0 100644 --- a/src/Converter.php +++ b/src/Converter.php @@ -14,12 +14,12 @@ interface Converter { /** - * @param TSource $source + * @param TSource $source * @param TContext $ctx * * @return TTarget target type of your conversion * * @throws ConverterException */ - public function convert(object $source, ?object $ctx = null): object; + public function convert(object $source, object $ctx = null): object; } diff --git a/src/Converter/GenericConverter.php b/src/Converter/GenericConverter.php index 99829f3..da15bfd 100644 --- a/src/Converter/GenericConverter.php +++ b/src/Converter/GenericConverter.php @@ -18,7 +18,7 @@ final class GenericConverter implements Converter { /** - * @param TargetFactory $factory + * @param TargetFactory $factory * @param array> $populators */ public function __construct( @@ -28,12 +28,12 @@ public function __construct( } /** - * @param TSource $source + * @param TSource $source * @param TContext $ctx * * @return TTarget */ - public function convert(object $source, ?object $ctx = null): object + public function convert(object $source, object $ctx = null): object { $target = $this->factory->create($ctx); diff --git a/src/Converter/StrategicConverter.php b/src/Converter/StrategicConverter.php index 87bbf3a..21695f7 100644 --- a/src/Converter/StrategicConverter.php +++ b/src/Converter/StrategicConverter.php @@ -19,7 +19,7 @@ final class StrategicConverter implements Converter { /** * @param array> $converters - * @param ConverterSelector $selector + * @param ConverterSelector $selector */ public function __construct( private array $converters, @@ -28,17 +28,17 @@ public function __construct( } /** - * @param TSource $source + * @param TSource $source * @param TContext $ctx * * @return TTarget */ - public function convert(object $source, ?object $ctx = null): object + public function convert(object $source, object $ctx = null): object { $selectedConverterKey = $this->selector->selectConverter($source, $ctx); - if (array_key_exists($selectedConverterKey, $this->converters)) { + if (\array_key_exists($selectedConverterKey, $this->converters)) { return $this->converters[$selectedConverterKey]->convert($source, $ctx); } - throw new ConverterException(sprintf("No converter found for key <%s>", $selectedConverterKey)); + throw new ConverterException(sprintf('No converter found for key <%s>', $selectedConverterKey)); } } diff --git a/src/Converter/Strategy/ConverterSelector.php b/src/Converter/Strategy/ConverterSelector.php index ad443fc..bf8fbbb 100644 --- a/src/Converter/Strategy/ConverterSelector.php +++ b/src/Converter/Strategy/ConverterSelector.php @@ -11,8 +11,8 @@ interface ConverterSelector { /** - * @param TSource $source + * @param TSource $source * @param TContext $ctx */ - public function selectConverter(object $source, ?object $ctx = null): string; + public function selectConverter(object $source, object $ctx = null): string; } diff --git a/src/DependencyInjection/NeustaConverterExtension.php b/src/DependencyInjection/NeustaConverterExtension.php index df4f544..732f24f 100644 --- a/src/DependencyInjection/NeustaConverterExtension.php +++ b/src/DependencyInjection/NeustaConverterExtension.php @@ -25,7 +25,7 @@ final class NeustaConverterExtension extends ConfigurableExtension */ public function loadInternal(array $mergedConfig, ContainerBuilder $container): void { - $loader = new YamlFileLoader($container, new FileLocator(dirname(__DIR__, 2) . '/config')); + $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config')); $loader->load('services.yaml'); foreach ($mergedConfig['converter'] as $converterId => $converter) { diff --git a/src/Exception/ConverterException.php b/src/Exception/ConverterException.php index dd27ad7..345d5e5 100644 --- a/src/Exception/ConverterException.php +++ b/src/Exception/ConverterException.php @@ -6,5 +6,4 @@ class ConverterException extends \Exception { - } diff --git a/src/Exception/PopulationException.php b/src/Exception/PopulationException.php index 1074dcc..95d61ee 100644 --- a/src/Exception/PopulationException.php +++ b/src/Exception/PopulationException.php @@ -9,7 +9,7 @@ class PopulationException extends \Exception public function __construct(string $sourcePropertyName, string $targetPropertyName, \Throwable $previous) { parent::__construct( - sprintf("Population Exception (%s -> %s): %s", + sprintf('Population Exception (%s -> %s): %s', $sourcePropertyName, $targetPropertyName, $previous->getMessage(), diff --git a/src/NeustaConverterBundle.php b/src/NeustaConverterBundle.php index 5b78695..35e0a9e 100644 --- a/src/NeustaConverterBundle.php +++ b/src/NeustaConverterBundle.php @@ -10,6 +10,6 @@ class NeustaConverterBundle extends Bundle { public function getPath(): string { - return __DIR__; + return \dirname(__DIR__); } } diff --git a/src/Populator.php b/src/Populator.php index dc7fae1..0978f68 100644 --- a/src/Populator.php +++ b/src/Populator.php @@ -12,9 +12,9 @@ interface Populator { /** - * @param TTarget $target - * @param TSource $source + * @param TTarget $target + * @param TSource $source * @param TContext $ctx */ - public function populate(object $target, object $source, ?object $ctx = null): void; + public function populate(object $target, object $source, object $ctx = null): void; } diff --git a/src/Populator/ArrayConvertingPopulator.php b/src/Populator/ArrayConvertingPopulator.php index be91fab..736893b 100644 --- a/src/Populator/ArrayConvertingPopulator.php +++ b/src/Populator/ArrayConvertingPopulator.php @@ -33,7 +33,7 @@ public function __construct( Converter $converter, string $sourceArrayPropertyName, string $targetPropertyName, - ?string $sourceArrayItemPropertyName = null, + string $sourceArrayItemPropertyName = null, PropertyAccessorInterface $arrayItemAccessor = null, PropertyAccessorInterface $accessor = null, ) { @@ -50,7 +50,7 @@ public function __construct( /** * @throws PopulationException */ - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { $this->populator->populate($target, $source, $ctx); } diff --git a/src/Populator/ArrayPropertyMappingPopulator.php b/src/Populator/ArrayPropertyMappingPopulator.php index ffe964d..1a4dffd 100644 --- a/src/Populator/ArrayPropertyMappingPopulator.php +++ b/src/Populator/ArrayPropertyMappingPopulator.php @@ -30,11 +30,11 @@ public function __construct( private string $targetProperty, private string $sourceArrayProperty, private ?string $sourceArrayItemProperty = null, - ?\Closure $mapper = null, + \Closure $mapper = null, PropertyAccessorInterface $arrayItemAccessor = null, PropertyAccessorInterface $accessor = null, ) { - $this->mapper = $mapper ?? static fn($v) => $v; + $this->mapper = $mapper ?? static fn ($v) => $v; $this->arrayItemAccessor = $arrayItemAccessor ?? PropertyAccess::createPropertyAccessor(); $this->accessor = $accessor ?? PropertyAccess::createPropertyAccessor(); } @@ -42,11 +42,11 @@ public function __construct( /** * @throws PopulationException */ - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { try { $unwrappedArray = array_map( - fn($item) => null !== $this->sourceArrayItemProperty + fn ($item) => null !== $this->sourceArrayItemProperty ? $this->arrayItemAccessor->getValue($item, $this->sourceArrayItemProperty) : $item, $this->accessor->getValue($source, $this->sourceArrayProperty), @@ -55,7 +55,7 @@ public function populate(object $target, object $source, ?object $ctx = null): v $this->accessor->setValue( $target, $this->targetProperty, - array_map(fn($item) => ($this->mapper)($item, $ctx), $unwrappedArray), + array_map(fn ($item) => ($this->mapper)($item, $ctx), $unwrappedArray), ); } catch (\Throwable $exception) { throw new PopulationException($this->sourceArrayProperty, $this->targetProperty, $exception); diff --git a/src/Populator/ContextMappingPopulator.php b/src/Populator/ContextMappingPopulator.php index 60dc11f..6f57522 100644 --- a/src/Populator/ContextMappingPopulator.php +++ b/src/Populator/ContextMappingPopulator.php @@ -29,7 +29,7 @@ final class ContextMappingPopulator implements Populator public function __construct( private string $targetProperty, private string $contextProperty, - ?\Closure $mapper = null, + \Closure $mapper = null, PropertyAccessorInterface $accessor = null, ) { $this->mapper = $mapper ?? static fn ($v) => $v; @@ -39,7 +39,7 @@ public function __construct( /** * @throws PopulationException */ - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { if (!$ctx || !$ctx->hasKey($this->contextProperty)) { return; diff --git a/src/Populator/ConvertingPopulator.php b/src/Populator/ConvertingPopulator.php index c72ac9d..5910361 100644 --- a/src/Populator/ConvertingPopulator.php +++ b/src/Populator/ConvertingPopulator.php @@ -46,7 +46,7 @@ public function __construct( /** * @throws PopulationException */ - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { $this->populator->populate($target, $source, $ctx); } diff --git a/src/Populator/PropertyMappingPopulator.php b/src/Populator/PropertyMappingPopulator.php index 36c2e90..af34a06 100644 --- a/src/Populator/PropertyMappingPopulator.php +++ b/src/Populator/PropertyMappingPopulator.php @@ -28,7 +28,7 @@ final class PropertyMappingPopulator implements Populator public function __construct( private string $targetProperty, private string $sourceProperty, - ?\Closure $mapper = null, + \Closure $mapper = null, PropertyAccessorInterface $accessor = null, ) { $this->mapper = $mapper ?? static fn ($v) => $v; @@ -38,7 +38,7 @@ public function __construct( /** * @throws PopulationException */ - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { try { $this->accessor->setValue( diff --git a/src/TargetFactory.php b/src/TargetFactory.php index 2620b86..100c8a2 100644 --- a/src/TargetFactory.php +++ b/src/TargetFactory.php @@ -15,5 +15,5 @@ interface TargetFactory * * @return TTarget */ - public function create(?object $ctx = null): object; + public function create(object $ctx = null): object; } diff --git a/tests/Converter/GenericConverterTest.php b/tests/Converter/GenericConverterTest.php index e03a943..65fd6db 100644 --- a/tests/Converter/GenericConverterTest.php +++ b/tests/Converter/GenericConverterTest.php @@ -5,12 +5,11 @@ namespace Neusta\ConverterBundle\Tests\Converter; use Neusta\ConverterBundle\Converter; -use Neusta\ConverterBundle\Converter\GenericConverter; use Neusta\ConverterBundle\Converter\Context\GenericContext; +use Neusta\ConverterBundle\Converter\GenericConverter; use Neusta\ConverterBundle\Populator\ContextMappingPopulator; -use Neusta\ConverterBundle\Populator\PropertyMappingPopulator; -use Neusta\ConverterBundle\Tests\Fixtures\Model\PersonFactory; use Neusta\ConverterBundle\Tests\Fixtures\Model\Person; +use Neusta\ConverterBundle\Tests\Fixtures\Model\PersonFactory; use Neusta\ConverterBundle\Tests\Fixtures\Model\User; use Neusta\ConverterBundle\Tests\Fixtures\Populator\PersonNamePopulator; use PHPUnit\Framework\TestCase; diff --git a/tests/Converter/StrategicConverterTest.php b/tests/Converter/StrategicConverterTest.php index f860491..e734e74 100644 --- a/tests/Converter/StrategicConverterTest.php +++ b/tests/Converter/StrategicConverterTest.php @@ -5,10 +5,10 @@ namespace Neusta\ConverterBundle\Tests\Converter; use Neusta\ConverterBundle\Converter; -use Neusta\ConverterBundle\Converter\StrategicConverter; use Neusta\ConverterBundle\Converter\Context\GenericContext; -use Neusta\ConverterBundle\Exception\ConverterException; +use Neusta\ConverterBundle\Converter\StrategicConverter; use Neusta\ConverterBundle\Converter\Strategy\ConverterSelector; +use Neusta\ConverterBundle\Exception\ConverterException; use Neusta\ConverterBundle\Tests\Fixtures\Model\Person; use Neusta\ConverterBundle\Tests\Fixtures\Model\User; use PHPUnit\Framework\TestCase; @@ -45,7 +45,6 @@ public function testConvert_regular_case(): void $this->converter->convert($user, null)->willReturn($person)->shouldBeCalled(); $this->strategyHandler->convert($user); - } public function testConvert_exceptional_case(): void @@ -67,9 +66,8 @@ public function testConvert_exceptional_case(): void $this->converter->convert($user, null)->willReturn($person)->shouldNotBeCalled(); $this->expectException(ConverterException::class); - $this->expectExceptionMessage("No converter found for key "); + $this->expectExceptionMessage('No converter found for key '); $this->strategyHandler->convert($user); - } } diff --git a/tests/Fixtures/Model/Address.php b/tests/Fixtures/Model/Address.php index 570e2bc..4bb79d0 100644 --- a/tests/Fixtures/Model/Address.php +++ b/tests/Fixtures/Model/Address.php @@ -16,9 +16,10 @@ public function getPostalCode(): string return $this->postalCode; } - public function setPostalCode(string $postalCode): Address + public function setPostalCode(string $postalCode): self { $this->postalCode = $postalCode; + return $this; } @@ -27,9 +28,10 @@ public function getCity(): string return $this->city; } - public function setCity(string $city): Address + public function setCity(string $city): self { $this->city = $city; + return $this; } @@ -38,9 +40,10 @@ public function getStreet(): string return $this->street; } - public function setStreet(string $street): Address + public function setStreet(string $street): self { $this->street = $street; + return $this; } @@ -49,9 +52,10 @@ public function getStreetNo(): string return $this->streetNo; } - public function setStreetNo(string $streetNo): Address + public function setStreetNo(string $streetNo): self { $this->streetNo = $streetNo; + return $this; } } diff --git a/tests/Fixtures/Model/AddressFactory.php b/tests/Fixtures/Model/AddressFactory.php index bdfc099..34d7132 100644 --- a/tests/Fixtures/Model/AddressFactory.php +++ b/tests/Fixtures/Model/AddressFactory.php @@ -12,7 +12,7 @@ */ class AddressFactory implements TargetFactory { - public function create(?object $ctx = null): PersonAddress + public function create(object $ctx = null): PersonAddress { return new PersonAddress(); } diff --git a/tests/Fixtures/Model/ContactNumber.php b/tests/Fixtures/Model/ContactNumber.php index 1b0ae76..75d71a3 100644 --- a/tests/Fixtures/Model/ContactNumber.php +++ b/tests/Fixtures/Model/ContactNumber.php @@ -8,22 +8,15 @@ class ContactNumber { private string $phoneNumber; - /** - * @return string - */ public function getPhoneNumber(): string { return $this->phoneNumber; } - /** - * @param string $phoneNumber - * @return ContactNumber - */ - public function setPhoneNumber(string $phoneNumber): ContactNumber + public function setPhoneNumber(string $phoneNumber): self { $this->phoneNumber = $phoneNumber; + return $this; } - } diff --git a/tests/Fixtures/Model/ContactNumberFactory.php b/tests/Fixtures/Model/ContactNumberFactory.php index e7dbeaf..cfb4dc9 100644 --- a/tests/Fixtures/Model/ContactNumberFactory.php +++ b/tests/Fixtures/Model/ContactNumberFactory.php @@ -12,7 +12,7 @@ */ class ContactNumberFactory implements TargetFactory { - public function create(?object $ctx = null): ContactNumber + public function create(object $ctx = null): ContactNumber { return new ContactNumber(); } diff --git a/tests/Fixtures/Model/Hobby.php b/tests/Fixtures/Model/Hobby.php index 23ac666..f5751fe 100644 --- a/tests/Fixtures/Model/Hobby.php +++ b/tests/Fixtures/Model/Hobby.php @@ -10,39 +10,27 @@ class Hobby private string $category; - /** - * @return string - */ public function getLabel(): string { return $this->label; } - /** - * @param string $label - * @return Hobby - */ - public function setLabel(string $label): Hobby + public function setLabel(string $label): self { $this->label = $label; + return $this; } - /** - * @return string - */ public function getCategory(): string { return $this->category; } - /** - * @param string $category - * @return Hobby - */ - public function setCategory(string $category): Hobby + public function setCategory(string $category): self { $this->category = $category; + return $this; } diff --git a/tests/Fixtures/Model/Person.php b/tests/Fixtures/Model/Person.php index ded0b51..a15a6d8 100644 --- a/tests/Fixtures/Model/Person.php +++ b/tests/Fixtures/Model/Person.php @@ -25,21 +25,15 @@ class Person /** @var array */ private array $contactNumbers; - /** - * @return array - */ public function getContactNumbers(): array { return $this->contactNumbers; } - /** - * @param array $contactNumbers - * @return Person - */ - public function setContactNumbers(array $contactNumbers): Person + public function setContactNumbers(array $contactNumbers): self { $this->contactNumbers = $contactNumbers; + return $this; } @@ -47,9 +41,11 @@ public function getFullName(): string { return $this->fullName; } - public function setFullName(?string $fullName): Person + + public function setFullName(?string $fullName): self { $this->fullName = $fullName; + return $this; } @@ -58,9 +54,10 @@ public function getAge(): ?int return $this->age; } - public function setAge(?int $age): Person + public function setAge(?int $age): self { $this->age = $age; + return $this; } @@ -69,57 +66,46 @@ public function getAddress(): ?PersonAddress return $this->address; } - public function setAddress(?PersonAddress $address): Person + public function setAddress(?PersonAddress $address): self { $this->address = $address; + return $this; } - /** - * @return array - */ public function getFavouriteMovies(): array { return $this->favouriteMovies; } - /** - * @param array $favouriteMovies - * @return Person - */ - public function setFavouriteMovies(array $favouriteMovies): Person + public function setFavouriteMovies(array $favouriteMovies): self { $this->favouriteMovies = $favouriteMovies; + return $this; } - /** - * @return array - */ public function getActivities(): array { return $this->activities; } - /** - * @param array $activities - * @return Person - */ - public function setActivities(array $activities): Person + public function setActivities(array $activities): self { $this->activities = $activities; + return $this; } - public function getLocale(): ?string { return $this->locale; } - public function setLocale(?string $locale): Person + public function setLocale(?string $locale): self { $this->locale = $locale; + return $this; } @@ -128,9 +114,10 @@ public function getGroup(): ?string return $this->group; } - public function setGroup(?string $group): Person + public function setGroup(?string $group): self { $this->group = $group; + return $this; } } diff --git a/tests/Fixtures/Model/PersonAddress.php b/tests/Fixtures/Model/PersonAddress.php index 20f336d..0e441d3 100644 --- a/tests/Fixtures/Model/PersonAddress.php +++ b/tests/Fixtures/Model/PersonAddress.php @@ -16,9 +16,10 @@ public function getPostalCode(): string return $this->postalCode; } - public function setPostalCode(string $postalCode): PersonAddress + public function setPostalCode(string $postalCode): self { $this->postalCode = $postalCode; + return $this; } @@ -27,9 +28,10 @@ public function getCity(): string return $this->city; } - public function setCity(string $city): PersonAddress + public function setCity(string $city): self { $this->city = $city; + return $this; } @@ -38,9 +40,10 @@ public function getStreet(): string return $this->street; } - public function setStreet(string $street): PersonAddress + public function setStreet(string $street): self { $this->street = $street; + return $this; } @@ -49,9 +52,10 @@ public function getStreetNo(): string return $this->streetNo; } - public function setStreetNo(string $streetNo): PersonAddress + public function setStreetNo(string $streetNo): self { $this->streetNo = $streetNo; + return $this; } } diff --git a/tests/Fixtures/Model/PersonFactory.php b/tests/Fixtures/Model/PersonFactory.php index 1c73976..163cfbd 100644 --- a/tests/Fixtures/Model/PersonFactory.php +++ b/tests/Fixtures/Model/PersonFactory.php @@ -12,7 +12,7 @@ */ class PersonFactory implements TargetFactory { - public function create(?object $ctx = null): Person + public function create(object $ctx = null): Person { return new Person(); } diff --git a/tests/Fixtures/Model/Phone.php b/tests/Fixtures/Model/Phone.php index 8c07fd8..8bdee72 100644 --- a/tests/Fixtures/Model/Phone.php +++ b/tests/Fixtures/Model/Phone.php @@ -9,40 +9,27 @@ class Phone private string $type; private string $number; - /** - * @return string - */ public function getType(): string { return $this->type; } - /** - * @param string $type - * @return Phone - */ - public function setType(string $type): Phone + public function setType(string $type): self { $this->type = $type; + return $this; } - /** - * @return string - */ public function getNumber(): string { return $this->number; } - /** - * @param string $number - * @return Phone - */ - public function setNumber(string $number): Phone + public function setNumber(string $number): self { $this->number = $number; + return $this; } - } diff --git a/tests/Fixtures/Model/UnknownType.php b/tests/Fixtures/Model/UnknownType.php index 3822212..7b834cb 100644 --- a/tests/Fixtures/Model/UnknownType.php +++ b/tests/Fixtures/Model/UnknownType.php @@ -6,5 +6,4 @@ class UnknownType { - -} \ No newline at end of file +} diff --git a/tests/Fixtures/Model/User.php b/tests/Fixtures/Model/User.php index c9a31f5..e463d83 100644 --- a/tests/Fixtures/Model/User.php +++ b/tests/Fixtures/Model/User.php @@ -29,7 +29,7 @@ public function getUuid(): int return $this->uuid; } - public function setUuid(int $uuid): User + public function setUuid(int $uuid): self { $this->uuid = $uuid; @@ -41,7 +41,7 @@ public function getFirstname(): string return $this->firstname; } - public function setFirstname(string $firstname): User + public function setFirstname(string $firstname): self { $this->firstname = $firstname; @@ -53,7 +53,7 @@ public function getLastname(): string return $this->lastname; } - public function setLastname(string $lastname): User + public function setLastname(string $lastname): self { $this->lastname = $lastname; @@ -65,9 +65,10 @@ public function getFullName(): string return $this->fullName; } - public function setFullName(string $fullName): User + public function setFullName(string $fullName): self { $this->fullName = $fullName; + return $this; } @@ -76,9 +77,10 @@ public function getAgeInYears(): int return $this->ageInYears; } - public function setAgeInYears($ageInYears): User + public function setAgeInYears($ageInYears): self { $this->ageInYears = $ageInYears; + return $this; } @@ -87,45 +89,34 @@ public function getAddress(): Address return $this->address; } - public function setAddress(Address $address): User + public function setAddress(Address $address): self { $this->address = $address; + return $this; } - /** - * @return array - */ public function getFavouriteMovies(): array { return $this->favouriteMovies; } - /** - * @param array $favouriteMovies - * @return User - */ - public function setFavouriteMovies(array $favouriteMovies): User + public function setFavouriteMovies(array $favouriteMovies): self { $this->favouriteMovies = $favouriteMovies; + return $this; } - /** - * @return array - */ public function getHobbies(): array { return $this->hobbies; } - /** - * @param array $hobbies - * @return User - */ - public function setHobbies(array $hobbies): User + public function setHobbies(array $hobbies): self { $this->hobbies = $hobbies; + return $this; } @@ -133,9 +124,11 @@ public function getFieldWithUnknownType(): UnknownType { return $this->fieldWithUnknownType; } - public function setFieldWithUnknownType(UnknownType $fieldWithUnknownType): User + + public function setFieldWithUnknownType(UnknownType $fieldWithUnknownType): self { $this->fieldWithUnknownType = $fieldWithUnknownType; + return $this; } @@ -149,12 +142,11 @@ public function getPhones(): array /** * @param array $phones - * @return User */ - public function setPhones(array $phones): User + public function setPhones(array $phones): self { $this->phones = $phones; + return $this; } - } diff --git a/tests/Fixtures/Populator/AddressPopulator.php b/tests/Fixtures/Populator/AddressPopulator.php index 8f67145..2104032 100644 --- a/tests/Fixtures/Populator/AddressPopulator.php +++ b/tests/Fixtures/Populator/AddressPopulator.php @@ -6,15 +6,15 @@ use Neusta\ConverterBundle\Converter\Context\GenericContext; use Neusta\ConverterBundle\Populator; -use Neusta\ConverterBundle\Tests\Fixtures\Model\PersonAddress; use Neusta\ConverterBundle\Tests\Fixtures\Model\Address; +use Neusta\ConverterBundle\Tests\Fixtures\Model\PersonAddress; /** * @implements Populator */ class AddressPopulator implements Populator { - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { $target->setStreet($source->getStreet()); $target->setStreetNo($source->getStreetNo()); diff --git a/tests/Fixtures/Populator/PersonNamePopulator.php b/tests/Fixtures/Populator/PersonNamePopulator.php index b04b77a..2a9931e 100644 --- a/tests/Fixtures/Populator/PersonNamePopulator.php +++ b/tests/Fixtures/Populator/PersonNamePopulator.php @@ -14,7 +14,7 @@ */ class PersonNamePopulator implements Populator { - public function populate(object $target, object $source, ?object $ctx = null): void + public function populate(object $target, object $source, object $ctx = null): void { $separator = ' '; if ($ctx?->hasKey('separator')) { @@ -25,7 +25,7 @@ public function populate(object $target, object $source, ?object $ctx = null): v $separator, [ $source->getFirstname(), - $source->getLastname() + $source->getLastname(), ] )); } diff --git a/tests/NeustaConverterBundleTest.php b/tests/NeustaConverterBundleTest.php index 2057169..7dd4d6d 100644 --- a/tests/NeustaConverterBundleTest.php +++ b/tests/NeustaConverterBundleTest.php @@ -11,6 +11,6 @@ class NeustaConverterBundleTest extends TestCase { public function testThatBundlePathIsCurrentDir(): void { - self::assertStringEndsWith('src', (new NeustaConverterBundle)->getPath()); + self::assertStringEndsNotWith('src', (new NeustaConverterBundle())->getPath()); } } diff --git a/tests/Populator/ArrayConvertingPopulatorIntegrationTest.php b/tests/Populator/ArrayConvertingPopulatorIntegrationTest.php index 5192c4f..3004005 100644 --- a/tests/Populator/ArrayConvertingPopulatorIntegrationTest.php +++ b/tests/Populator/ArrayConvertingPopulatorIntegrationTest.php @@ -5,9 +5,6 @@ namespace Neusta\ConverterBundle\Tests\Populator; use Neusta\ConverterBundle\Populator\ArrayConvertingPopulator; -use Neusta\ConverterBundle\Populator\ArrayPropertyMappingPopulator; -use Neusta\ConverterBundle\Populator\PropertyMappingPopulator; -use Neusta\ConverterBundle\Tests\Fixtures\Model\Hobby; use Neusta\ConverterBundle\Tests\Fixtures\Model\Person; use Neusta\ConverterBundle\Tests\Fixtures\Model\Phone; use Neusta\ConverterBundle\Tests\Fixtures\Model\User; @@ -29,7 +26,7 @@ public function testPopulate(): void $phone2 = (new Phone())->setType('mobile')->setNumber('0172 2456543'); $phone3 = (new Phone())->setType('home')->setNumber('0421 2456543'); - $user = (new User())->setPhones([$phone1, $phone2, $phone3,]); + $user = (new User())->setPhones([$phone1, $phone2, $phone3]); $person = new Person(); $this->populator->populate($person, $user); diff --git a/tests/Populator/ArrayPropertyMappingPopulatorIntegrationTest.php b/tests/Populator/ArrayPropertyMappingPopulatorIntegrationTest.php index b9571f6..b4f9089 100644 --- a/tests/Populator/ArrayPropertyMappingPopulatorIntegrationTest.php +++ b/tests/Populator/ArrayPropertyMappingPopulatorIntegrationTest.php @@ -4,9 +4,7 @@ namespace Neusta\ConverterBundle\Tests\Populator; -use Neusta\ConverterBundle\Populator\ArrayConvertingPopulator; use Neusta\ConverterBundle\Populator\ArrayPropertyMappingPopulator; -use Neusta\ConverterBundle\Populator\PropertyMappingPopulator; use Neusta\ConverterBundle\Tests\Fixtures\Model\Hobby; use Neusta\ConverterBundle\Tests\Fixtures\Model\Person; use Neusta\ConverterBundle\Tests\Fixtures\Model\User; diff --git a/tests/Populator/ArrayPropertyMappingPopulatorTest.php b/tests/Populator/ArrayPropertyMappingPopulatorTest.php index 3e995f1..a82a666 100644 --- a/tests/Populator/ArrayPropertyMappingPopulatorTest.php +++ b/tests/Populator/ArrayPropertyMappingPopulatorTest.php @@ -34,7 +34,7 @@ public function test_populateWithoutInnerProperty(): void public function test_populateWithInnerProperty(): void { - $populator = new ArrayPropertyMappingPopulator('activities', 'hobbies','label'); + $populator = new ArrayPropertyMappingPopulator('activities', 'hobbies', 'label'); $user = (new User())->setHobbies([ (new Hobby())->setLabel('reading'), (new Hobby())->setLabel('swimming'), diff --git a/tests/Populator/ContextMappingPopulatorTest.php b/tests/Populator/ContextMappingPopulatorTest.php index 6aec648..5f9a635 100644 --- a/tests/Populator/ContextMappingPopulatorTest.php +++ b/tests/Populator/ContextMappingPopulatorTest.php @@ -7,7 +7,6 @@ use Neusta\ConverterBundle\Converter\Context\GenericContext; use Neusta\ConverterBundle\Exception\PopulationException; use Neusta\ConverterBundle\Populator\ContextMappingPopulator; -use Neusta\ConverterBundle\Populator\PropertyMappingPopulator; use Neusta\ConverterBundle\Tests\Fixtures\Model\Person; use Neusta\ConverterBundle\Tests\Fixtures\Model\User; use PHPUnit\Framework\TestCase; diff --git a/tests/app/config/services.yaml b/tests/app/config/services.yaml index b959f14..22b184a 100644 --- a/tests/app/config/services.yaml +++ b/tests/app/config/services.yaml @@ -1,61 +1,63 @@ services: - _defaults: - autowire: true - autoconfigure: true - # for tests only - public: true - - test.address.converter: - parent: 'neusta_converter.generic_converter' - public: true - arguments: - $factory: '@Neusta\ConverterBundle\Tests\Fixtures\Model\AddressFactory' - $populators: - - '@Neusta\ConverterBundle\Tests\Fixtures\Populator\AddressPopulator' - - Neusta\ConverterBundle\Tests\Fixtures\Populator\PersonNamePopulator: ~ - Neusta\ConverterBundle\Tests\Fixtures\Populator\AddressPopulator: ~ - - test.person.wrong.source.type.populator: - parent: 'neusta_converter.converting_populator' - public: true - arguments: - $converter: '@test.address.converter' - $sourcePropertyName: 'fieldWithUnknownType' - $targetPropertyName: 'address' - - test.person.wrong.converter.populator: - parent: 'neusta_converter.converting_populator' - public: true - arguments: - $converter: '@test.person.converter' # wrong converter for testing - $sourcePropertyName: 'address' - $targetPropertyName: 'address' - - - test.person.fullName.populator: - parent: 'neusta_converter.property_mapping_populator' - public: true - arguments: - $targetProperty: 'fullName' - $sourceProperty: 'fullName' - - test.person.activities.populator: - parent: 'neusta_converter.array_property_mapping_populator' - public: true - arguments: - $sourceArrayItemProperty: 'label' - $sourceArrayProperty: 'hobbies' - $targetProperty: 'activities' - - test.person.contactnumbers.populator: - parent: 'neusta_converter.array_converting_populator' - public: true - arguments: - $converter: '@test.contactnumber.converter' - $sourceArrayPropertyName: 'phones' - $targetPropertyName: 'contactNumbers' - - Neusta\ConverterBundle\Tests\Fixtures\Model\PersonFactory: ~ - Neusta\ConverterBundle\Tests\Fixtures\Model\AddressFactory: ~ - Neusta\ConverterBundle\Tests\Fixtures\Model\ContactNumberFactory: ~ + _defaults: + autowire: true + autoconfigure: true + # for tests only + public: true + + test.address.converter: + parent: 'neusta_converter.generic_converter' + public: true + arguments: + $factory: '@Neusta\ConverterBundle\Tests\Fixtures\Model\AddressFactory' + $populators: + - '@Neusta\ConverterBundle\Tests\Fixtures\Populator\AddressPopulator' + + Neusta\ConverterBundle\Tests\Fixtures\Populator\PersonNamePopulator: ~ + Neusta\ConverterBundle\Tests\Fixtures\Populator\AddressPopulator: ~ + + + + test.person.wrong.source.type.populator: + parent: 'neusta_converter.converting_populator' + public: true + arguments: + $converter: '@test.address.converter' + $sourcePropertyName: 'fieldWithUnknownType' + $targetPropertyName: 'address' + + test.person.wrong.converter.populator: + parent: 'neusta_converter.converting_populator' + public: true + arguments: + $converter: '@test.person.converter' # wrong converter for testing + $sourcePropertyName: 'address' + $targetPropertyName: 'address' + + + test.person.fullName.populator: + parent: 'neusta_converter.property_mapping_populator' + public: true + arguments: + $targetProperty: 'fullName' + $sourceProperty: 'fullName' + + test.person.activities.populator: + parent: 'neusta_converter.array_property_mapping_populator' + public: true + arguments: + $sourceArrayItemProperty: 'label' + $sourceArrayProperty: 'hobbies' + $targetProperty: 'activities' + + test.person.contactnumbers.populator: + parent: 'neusta_converter.array_converting_populator' + public: true + arguments: + $converter: '@test.contactnumber.converter' + $sourceArrayPropertyName: 'phones' + $targetPropertyName: 'contactNumbers' + + Neusta\ConverterBundle\Tests\Fixtures\Model\PersonFactory: ~ + Neusta\ConverterBundle\Tests\Fixtures\Model\AddressFactory: ~ + Neusta\ConverterBundle\Tests\Fixtures\Model\ContactNumberFactory: ~