From 0a93b8ebc79065775ae6bb5f816ab957ac70e65a Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 11 Jan 2024 09:32:04 +0100 Subject: [PATCH 1/9] Fixed conditional mapper : elseif conditions were not correctly use --- src/Builder/ArrayMapper.php | 2 +- src/Builder/ConditionalMapper.php | 10 ++++------ src/Builder/ObjectMapper.php | 2 +- src/Builder/Transformer.php | 8 ++++---- src/Factory/ArrayMapper.php | 4 ++-- src/Factory/ConditionalMapper.php | 10 +++++----- src/Factory/ObjectMapper.php | 4 ++-- src/Factory/Repository/RepositoryTrait.php | 2 +- src/Service.php | 8 ++++---- 9 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/Builder/ArrayMapper.php b/src/Builder/ArrayMapper.php index d4da66d..06e16b1 100644 --- a/src/Builder/ArrayMapper.php +++ b/src/Builder/ArrayMapper.php @@ -25,7 +25,7 @@ public function getNode(): Node name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), + new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), ], 'stmts' => [ new Node\Stmt\ClassMethod( diff --git a/src/Builder/ConditionalMapper.php b/src/Builder/ConditionalMapper.php index 876f59b..8501441 100644 --- a/src/Builder/ConditionalMapper.php +++ b/src/Builder/ConditionalMapper.php @@ -35,15 +35,13 @@ private function compileConditions(array $alternatives): Node /** @var Builder $builder */ [$condition, $builder] = array_shift($alternatives); - /** @var Node\Stmt\Expression $expression */ - $expression = $parser->parse('interpreter->compile($condition, ['input', 'output']).';')[0]; return new Node\Expr\New_( new Node\Stmt\Class_( name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), + new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), ], 'stmts' => [ new Node\Stmt\Property( @@ -108,7 +106,7 @@ function ($alternative) { ], 'stmts' => [ new Node\Stmt\If_( - cond: $expression->expr, + cond: $parser->parse('interpreter->compile($condition, ['input', 'output']).';')[0]->expr ?? throw new \UnexpectedValueException('Expected parsing result to be an instance of Node\Expr.'), subNodes: [ 'stmts' => [ new Node\Stmt\Return_( @@ -132,11 +130,11 @@ function ($alternative) { ), ], 'elseifs' => array_map( - function ($alternative, $index) use ($expression) { + function ($alternative, $index) use ($parser) { [$condition, $repository] = $alternative; return new Node\Stmt\ElseIf_( - cond: $expression->expr, + cond: $parser->parse('interpreter->compile($condition, ['input', 'output']).';')[0]->expr ?? throw new \UnexpectedValueException('Expected parsing result to be an instance of Node\Expr.'), stmts: [ new Node\Stmt\Return_( new Node\Expr\FuncCall( diff --git a/src/Builder/ObjectMapper.php b/src/Builder/ObjectMapper.php index 3b0ad8d..d637cd2 100644 --- a/src/Builder/ObjectMapper.php +++ b/src/Builder/ObjectMapper.php @@ -25,7 +25,7 @@ public function getNode(): Node name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), + new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), ], 'stmts' => [ new Node\Stmt\ClassMethod( diff --git a/src/Builder/Transformer.php b/src/Builder/Transformer.php index 7aba496..bfeeb95 100644 --- a/src/Builder/Transformer.php +++ b/src/Builder/Transformer.php @@ -37,7 +37,7 @@ class: new Node\Stmt\Class_( name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified(\Kiboko\Contract\Pipeline\TransformerInterface::class), + new Node\Name\FullyQualified('Kiboko\\Contract\\Pipeline\\TransformerInterface'), ], 'stmts' => [ new Node\Stmt\ClassMethod( @@ -74,7 +74,7 @@ class: new Node\Stmt\Class_( expr: new Node\Expr\Yield_( new Node\Expr\New_( class: new Node\Name\FullyQualified( - \Kiboko\Component\Bucket\AcceptanceResultBucket::class + 'Kiboko\\Component\\Bucket\\AcceptanceResultBucket' ), args: [ new Node\Arg( @@ -110,7 +110,7 @@ class: new Node\Name\FullyQualified( new Node\Expr\Yield_( new Node\Expr\New_( class: new Node\Name\FullyQualified( - \Kiboko\Component\Bucket\AcceptanceResultBucket::class, + 'Kiboko\\Component\\Bucket\\AcceptanceResultBucket', ), args: [ new Node\Arg( @@ -121,7 +121,7 @@ class: new Node\Name\FullyQualified( ) ), ], - 'returnType' => new Node\Name\FullyQualified(\Generator::class), + 'returnType' => new Node\Name\FullyQualified('Generator'), ], ), ], diff --git a/src/Factory/ArrayMapper.php b/src/Factory/ArrayMapper.php index 13a05a1..cfd911f 100644 --- a/src/Factory/ArrayMapper.php +++ b/src/Factory/ArrayMapper.php @@ -36,7 +36,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -73,7 +73,7 @@ public function compile(array $config): Repository\TransformerMapper try { return new Repository\TransformerMapper($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Factory/ConditionalMapper.php b/src/Factory/ConditionalMapper.php index 672958f..9976349 100644 --- a/src/Factory/ConditionalMapper.php +++ b/src/Factory/ConditionalMapper.php @@ -39,7 +39,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -86,7 +86,7 @@ public function compile(array $config): Repository\TransformerMapper $alternative['condition'], $mapperBuilder ); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } elseif (\array_key_exists('object', $alternative)) { @@ -113,13 +113,13 @@ className: $alternative['object']['class'], $alternative['condition'], $mapperBuilder ); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } else { throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.'); } - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -128,7 +128,7 @@ className: $alternative['object']['class'], return new Repository\TransformerMapper( new FastMap\Builder\Transformer($builder), ); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Factory/ObjectMapper.php b/src/Factory/ObjectMapper.php index 5394578..63a2042 100644 --- a/src/Factory/ObjectMapper.php +++ b/src/Factory/ObjectMapper.php @@ -35,7 +35,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -67,7 +67,7 @@ className: $config['class'], try { return new Repository\TransformerMapper($builder); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new Configurator\InvalidConfigurationException(message: $exception->getMessage(), previous: $exception); } } diff --git a/src/Factory/Repository/RepositoryTrait.php b/src/Factory/Repository/RepositoryTrait.php index 3374c96..c7ddabb 100644 --- a/src/Factory/Repository/RepositoryTrait.php +++ b/src/Factory/Repository/RepositoryTrait.php @@ -15,7 +15,7 @@ trait RepositoryTrait /** @var string[] */ private array $packages; - public function addFiles(FileInterface|DirectoryInterface ...$files): Configurator\RepositoryInterface + public function addFiles(DirectoryInterface|FileInterface ...$files): Configurator\RepositoryInterface { array_push($this->files, ...$files); diff --git a/src/Service.php b/src/Service.php index d202139..55f1fa0 100644 --- a/src/Service.php +++ b/src/Service.php @@ -14,7 +14,7 @@ #[Configurator\Pipeline( name: 'fastmap', dependencies: [ - 'php-etl/mapping-contracts:0.4.*' + 'php-etl/mapping-contracts:0.4.*', ], steps: [ new Configurator\Pipeline\StepTransformer(null), @@ -50,7 +50,7 @@ public function normalize(array $config): array { try { return $this->processor->processConfiguration($this->configuration, $config); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new InvalidConfigurationException($exception->getMessage(), 0, $exception); } } @@ -61,7 +61,7 @@ public function validate(array $config): bool $this->processor->processConfiguration($this->configuration, $config); return true; - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException) { return false; } } @@ -99,7 +99,7 @@ public function compile(array $config): Factory\Repository\TransformerMapper return $objectFactory->compile($config['object']); } throw new InvalidConfigurationException('Could not determine if the factory should build an array or an object transformer.'); - } catch (Symfony\InvalidTypeException|Symfony\InvalidConfigurationException $exception) { + } catch (Symfony\InvalidConfigurationException|Symfony\InvalidTypeException $exception) { throw new InvalidConfigurationException($exception->getMessage(), 0, $exception); } } From bc238ecde9881566be6c24297ed4f51af25f6b32 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 11 Jan 2024 08:35:24 +0000 Subject: [PATCH 2/9] [rector] Rector fixes --- src/Builder/ArrayMapper.php | 2 +- src/Builder/ConditionalMapper.php | 2 +- src/Builder/ObjectMapper.php | 2 +- src/Builder/Transformer.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Builder/ArrayMapper.php b/src/Builder/ArrayMapper.php index 06e16b1..d4da66d 100644 --- a/src/Builder/ArrayMapper.php +++ b/src/Builder/ArrayMapper.php @@ -25,7 +25,7 @@ public function getNode(): Node name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), + new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), ], 'stmts' => [ new Node\Stmt\ClassMethod( diff --git a/src/Builder/ConditionalMapper.php b/src/Builder/ConditionalMapper.php index 8501441..b6901ce 100644 --- a/src/Builder/ConditionalMapper.php +++ b/src/Builder/ConditionalMapper.php @@ -41,7 +41,7 @@ private function compileConditions(array $alternatives): Node name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), + new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), ], 'stmts' => [ new Node\Stmt\Property( diff --git a/src/Builder/ObjectMapper.php b/src/Builder/ObjectMapper.php index d637cd2..3b0ad8d 100644 --- a/src/Builder/ObjectMapper.php +++ b/src/Builder/ObjectMapper.php @@ -25,7 +25,7 @@ public function getNode(): Node name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified('Kiboko\\Contract\\Mapping\\CompiledMapperInterface'), + new Node\Name\FullyQualified(\Kiboko\Contract\Mapping\CompiledMapperInterface::class), ], 'stmts' => [ new Node\Stmt\ClassMethod( diff --git a/src/Builder/Transformer.php b/src/Builder/Transformer.php index bfeeb95..397a9bd 100644 --- a/src/Builder/Transformer.php +++ b/src/Builder/Transformer.php @@ -37,7 +37,7 @@ class: new Node\Stmt\Class_( name: null, subNodes: [ 'implements' => [ - new Node\Name\FullyQualified('Kiboko\\Contract\\Pipeline\\TransformerInterface'), + new Node\Name\FullyQualified(\Kiboko\Contract\Pipeline\TransformerInterface::class), ], 'stmts' => [ new Node\Stmt\ClassMethod( From 125fa740822a5f1df7919e37dd376e0168f2f063 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 11 Jan 2024 16:38:30 +0100 Subject: [PATCH 3/9] Added tests for the array mapper and the conditional mapper --- tests/functional/Builder/ArrayMapperTest.php | 72 ++++++++++ tests/functional/Builder/BuilderTestCase.php | 80 +++++++++++ .../Builder/ConditionalMapperTest.php | 128 ++++++++++++++++++ tests/functional/PipelineRunner.php | 39 ++++++ 4 files changed, 319 insertions(+) create mode 100644 tests/functional/Builder/ArrayMapperTest.php create mode 100644 tests/functional/Builder/BuilderTestCase.php create mode 100644 tests/functional/Builder/ConditionalMapperTest.php create mode 100644 tests/functional/PipelineRunner.php diff --git a/tests/functional/Builder/ArrayMapperTest.php b/tests/functional/Builder/ArrayMapperTest.php new file mode 100644 index 0000000..23f24c4 --- /dev/null +++ b/tests/functional/Builder/ArrayMapperTest.php @@ -0,0 +1,72 @@ +children()->copy('[id]', '[identifier]'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + [ + 'identifier' => 1, + 'enabled' => true, + ] + ], + [ + [ + 'id' => 1, + ] + ], + $builder, + ); + } + + public function testWithSeveralConditionsThatMatch() + { + $builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper( + $mapper = new ArrayBuilder() + ); + + $mapper->children()->copy('[id]', '[identifier]'); + $mapper->children()->copy('[enabled]', '[enabled]'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + [ + 'identifier' => 1, + 'enabled' => true, + ] + ], + [ + [ + 'id' => 1, + 'enabled' => true, + ] + ], + $builder, + ); + } +} diff --git a/tests/functional/Builder/BuilderTestCase.php b/tests/functional/Builder/BuilderTestCase.php new file mode 100644 index 0000000..2a0606c --- /dev/null +++ b/tests/functional/Builder/BuilderTestCase.php @@ -0,0 +1,80 @@ +fs = vfsStream::setup('root'); + } + + protected function tearDown(): void + { + $this->fs = null; + } + + protected function getBuilderCompilePath(): string + { + return $this->fs->url(); + } + + public function pipelineRunner(): PipelineRunnerInterface + { + return new PipelineRunner(); + } + + protected function assertNodeIsInstanceOf(string $expected, DefaultBuilder $builder, string $message = ''): void + { + $printer = new PrettyPrinter\Standard(); + + try { + $filename = sha1(random_bytes(128)) .'.php'; + $file = new vfsStreamFile($filename); + $file->setContent($printer->prettyPrintFile([ + new Node\Stmt\Return_($builder->getNode()), + ])); + $this->fs->addChild($file); + + $actual = include vfsStream::url('root/'.$filename); + } catch (\ParseError $exception) { + echo $printer->prettyPrintFile([$builder->getNode()]); + $this->fail($exception->getMessage()); + } + + $this->assertInstanceOf($expected, $actual, $message); + } + + protected function assertNodeIsNotInstanceOf(string $expected, DefaultBuilder $builder, string $message = ''): void + { + $printer = new PrettyPrinter\Standard(); + + try { + $filename = sha1(random_bytes(128)) .'.php'; + $file = new vfsStreamFile($filename); + $file->setContent($printer->prettyPrintFile([ + new Node\Stmt\Return_($builder->getNode()), + ])); + $this->fs->addChild($file); + + $actual = include vfsStream::url('root/'.$filename); + } catch (\ParseError $exception) { + echo $printer->prettyPrintFile([$builder->getNode()]); + $this->fail($exception->getMessage()); + } + + $this->assertNotInstanceOf($expected, $actual, $message); + } +} diff --git a/tests/functional/Builder/ConditionalMapperTest.php b/tests/functional/Builder/ConditionalMapperTest.php new file mode 100644 index 0000000..4e7807c --- /dev/null +++ b/tests/functional/Builder/ConditionalMapperTest.php @@ -0,0 +1,128 @@ +withAlternative( + 'input["enable"] == true', + new ArrayMapper( + $mapper = new ArrayAppendBuilder( + interpreter: $interpreter, + ), + ) + ); + + $mapper->children()->constant('[updated_at]', '2024-01-11'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + [ + 'identifier' => 1, + 'enable' => true, + ] + ], + [ + [ + 'identifier' => 1, + 'enable' => true, + 'updated_at' => '2024-01-11' + ] + ], + $builder, + ); + } + + public function testWithSeveralConditionsThatMatch() + { + $builder = new \Kiboko\Plugin\FastMap\Builder\ConditionalMapper($interpreter = new ExpressionLanguage()); + $mapperBuilder = new ArrayMapper( + $mapper = new ArrayAppendBuilder( + interpreter: $interpreter, + ), + ); + + $builder->withAlternative( + 'input["enable"] == true', + $mapperBuilder + ); + + $builder->withAlternative( + 'input["identifier"] === 1', + $mapperBuilder + ); + + $mapper->children()->constant('[updated_at]', '2024-01-11'); + $mapper->children()->constant('[price]', '19.99'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + [ + 'identifier' => 1, + 'enable' => true, + ] + ], + [ + [ + 'identifier' => 1, + 'enable' => true, + 'updated_at' => '2024-01-11', + 'price' => 19.99 + ] + ], + $builder, + ); + } + + public function testWithConditionThatDoesNotMatch() + { + $builder = new \Kiboko\Plugin\FastMap\Builder\ConditionalMapper($interpreter = new ExpressionLanguage()); + + $builder->withAlternative( + 'input["identifier"] === 0', + new ArrayMapper( + $mapper = new ArrayAppendBuilder( + interpreter: $interpreter, + ), + ) + ); + + $mapper->children()->constant('[updated_at]', '2024-01-11'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + [ + 'identifier' => 1, + 'enabled' => true, + ] + ], + [ + [ + 'identifier' => 1, + 'enabled' => true, + ] + ], + $builder, + ); + } +} diff --git a/tests/functional/PipelineRunner.php b/tests/functional/PipelineRunner.php new file mode 100644 index 0000000..374425d --- /dev/null +++ b/tests/functional/PipelineRunner.php @@ -0,0 +1,39 @@ +rewind(); + $async->rewind(); + + while ($source->valid() && $async->valid()) { + $bucket = $async->send($source->current()); + + if ($bucket instanceof RejectionResultBucketInterface) { + foreach ($bucket->walkRejection() as $line) { + $rejection->reject($line); + $state->reject(); + } + } + if ($bucket instanceof AcceptanceResultBucketInterface) { + yield from $bucket->walkAcceptance(); + $state->accept(); + } + + $source->next(); + } + } +} From 6d960484642bfcb05e3b7351e232f1959e50d308 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 11 Jan 2024 17:19:06 +0100 Subject: [PATCH 4/9] Updated php-etl/phpunit-extension --- .github/workflows/infection.yaml | 4 +- composer.json | 5 +- composer.lock | 176 ++++++++++++++++++++----------- 3 files changed, 121 insertions(+), 64 deletions(-) diff --git a/.github/workflows/infection.yaml b/.github/workflows/infection.yaml index 6712e59..8e031b2 100644 --- a/.github/workflows/infection.yaml +++ b/.github/workflows/infection.yaml @@ -23,8 +23,8 @@ jobs: - name: Infection run: | - wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar - wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc + wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar + wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar.asc chmod +x infection.phar ./infection.phar diff --git a/composer.json b/composer.json index 79d21d7..3a149a3 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,13 @@ "php-etl/fast-map-config": "*", "php-etl/packaging-contracts": "0.3.*", "php-etl/satellite-toolbox": "*", - "php-etl/configurator-contracts": "0.8.*" + "php-etl/configurator-contracts": "0.8.*", + "php-etl/bucket": "*" }, "require-dev": { "phpunit/phpunit": "^10.0", "phpunit/php-invoker": "*", - "php-etl/phpunit-extension": "0.7.*", + "php-etl/phpunit-extension": "*", "friendsofphp/php-cs-fixer": "^3.38", "phpstan/phpstan": "^1.10", "rector/rector": "^0.15", diff --git a/composer.lock b/composer.lock index ed06d8a..e0ea101 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "083e7a270c34b5ce40d220559e81ff27", + "content-hash": "a994335b75c4bd8e3b01061ce7ab77c4", "packages": [ { "name": "doctrine/inflector", @@ -153,6 +153,116 @@ }, "time": "2023-08-13T19:53:39+00:00" }, + { + "name": "php-etl/bucket", + "version": "v0.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-etl/bucket.git", + "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-etl/bucket/zipball/8b3f318398ceaca1fb25154ff8a06adf175b1c31", + "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31", + "shasum": "" + }, + "require": { + "php": "^8.2", + "php-etl/bucket-contracts": "0.3.*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.38", + "phpspec/phpspec": "^7.3", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.15" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Kiboko\\Component\\Bucket\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kiboko SAS", + "homepage": "http://kiboko.fr" + }, + { + "name": "Grégory Planchat", + "email": "gregory@kiboko.fr" + } + ], + "description": "This library implements the Extract-Transform-Load pattern asynchronously in PHP with the help of iterators and generators", + "support": { + "issues": "https://github.com/php-etl/bucket/issues", + "source": "https://github.com/php-etl/bucket/tree/v0.4.0" + }, + "time": "2023-11-16T15:32:18+00:00" + }, + { + "name": "php-etl/bucket-contracts", + "version": "v0.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-etl/bucket-contracts.git", + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/64170754cb1f5e556c8e526177be51d905c3b15f", + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f", + "shasum": "" + }, + "require": { + "php": "^8.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.15" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Kiboko\\Contract\\Bucket\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kiboko SAS", + "homepage": "http://kiboko.fr" + }, + { + "name": "Grégory Planchatn rules", + "email": "gregory@kiboko.fr" + } + ], + "description": "This library describes contracts for the data-interchange buckets.", + "support": { + "issues": "https://github.com/php-etl/bucket-contracts/issues", + "source": "https://github.com/php-etl/bucket-contracts/tree/v0.3.0" + }, + "time": "2023-11-14T14:39:36+00:00" + }, { "name": "php-etl/configurator-contracts", "version": "v0.8.0", @@ -3396,72 +3506,18 @@ }, "time": "2022-02-21T01:04:05+00:00" }, - { - "name": "php-etl/bucket-contracts", - "version": "v0.3.0", - "source": { - "type": "git", - "url": "https://github.com/php-etl/bucket-contracts.git", - "reference": "64170754cb1f5e556c8e526177be51d905c3b15f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/64170754cb1f5e556c8e526177be51d905c3b15f", - "reference": "64170754cb1f5e556c8e526177be51d905c3b15f", - "shasum": "" - }, - "require": { - "php": "^8.2" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "phpstan/phpstan": "^1.10", - "rector/rector": "^0.15" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Kiboko\\Contract\\Bucket\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kiboko SAS", - "homepage": "http://kiboko.fr" - }, - { - "name": "Grégory Planchatn rules", - "email": "gregory@kiboko.fr" - } - ], - "description": "This library describes contracts for the data-interchange buckets.", - "support": { - "issues": "https://github.com/php-etl/bucket-contracts/issues", - "source": "https://github.com/php-etl/bucket-contracts/tree/v0.3.0" - }, - "time": "2023-11-14T14:39:36+00:00" - }, { "name": "php-etl/phpunit-extension", "version": "dev-main", "source": { "type": "git", "url": "https://github.com/php-etl/phpunit-extension.git", - "reference": "fd1758d8fc3d353de2b3f4e9ba0c1e7af92b19f3" + "reference": "5a612872d8a7275adc31be2c8f2f625d341b5326" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-etl/phpunit-extension/zipball/fd1758d8fc3d353de2b3f4e9ba0c1e7af92b19f3", - "reference": "fd1758d8fc3d353de2b3f4e9ba0c1e7af92b19f3", + "url": "https://api.github.com/repos/php-etl/phpunit-extension/zipball/5a612872d8a7275adc31be2c8f2f625d341b5326", + "reference": "5a612872d8a7275adc31be2c8f2f625d341b5326", "shasum": "" }, "require": { @@ -3508,7 +3564,7 @@ "issues": "https://github.com/php-etl/phpunit-extension/issues", "source": "https://github.com/php-etl/phpunit-extension/tree/main" }, - "time": "2023-11-16T15:32:17+00:00" + "time": "2023-11-21T12:56:00+00:00" }, { "name": "php-etl/pipeline-contracts", @@ -6730,5 +6786,5 @@ "ext-json": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } From 4f0bac5b53e541ef9596b99184c976bbb6f3e33e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 11 Jan 2024 16:19:51 +0000 Subject: [PATCH 5/9] [rector] Rector fixes --- src/Builder/Transformer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Builder/Transformer.php b/src/Builder/Transformer.php index 397a9bd..5c7e7da 100644 --- a/src/Builder/Transformer.php +++ b/src/Builder/Transformer.php @@ -74,7 +74,7 @@ class: new Node\Stmt\Class_( expr: new Node\Expr\Yield_( new Node\Expr\New_( class: new Node\Name\FullyQualified( - 'Kiboko\\Component\\Bucket\\AcceptanceResultBucket' + \Kiboko\Component\Bucket\AcceptanceResultBucket::class ), args: [ new Node\Arg( @@ -110,7 +110,7 @@ class: new Node\Name\FullyQualified( new Node\Expr\Yield_( new Node\Expr\New_( class: new Node\Name\FullyQualified( - 'Kiboko\\Component\\Bucket\\AcceptanceResultBucket', + \Kiboko\Component\Bucket\AcceptanceResultBucket::class, ), args: [ new Node\Arg( From b4522916faee20ecee38c074f8a65d890d83cb60 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 11 Jan 2024 17:22:34 +0100 Subject: [PATCH 6/9] Updated phpunit configuration --- phpunit.xml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index eadaa79..89b9b4d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - - - tests/functional/ - - - - - src - - - - - + + + tests/functional/ + + + + + + + + + src + + From 77123b3a2cba1c132c0dcf0ce41c6c49db684152 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 11 Jan 2024 17:25:01 +0100 Subject: [PATCH 7/9] Added php-etl/bucket into dev packages --- composer.json | 6 +- composer.lock | 222 +++++++++++++++++++++++++------------------------- 2 files changed, 114 insertions(+), 114 deletions(-) diff --git a/composer.json b/composer.json index 3a149a3..367b2c2 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "php-etl/fast-map-config": "*", "php-etl/packaging-contracts": "0.3.*", "php-etl/satellite-toolbox": "*", - "php-etl/configurator-contracts": "0.8.*", - "php-etl/bucket": "*" + "php-etl/configurator-contracts": "0.8.*" }, "require-dev": { "phpunit/phpunit": "^10.0", @@ -29,7 +28,8 @@ "friendsofphp/php-cs-fixer": "^3.38", "phpstan/phpstan": "^1.10", "rector/rector": "^0.15", - "infection/infection": "^0.26" + "infection/infection": "^0.26", + "php-etl/bucket": "*" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index e0ea101..0b6889d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a994335b75c4bd8e3b01061ce7ab77c4", + "content-hash": "996b345de97e205b43247c2cb1f7166d", "packages": [ { "name": "doctrine/inflector", @@ -153,116 +153,6 @@ }, "time": "2023-08-13T19:53:39+00:00" }, - { - "name": "php-etl/bucket", - "version": "v0.4.0", - "source": { - "type": "git", - "url": "https://github.com/php-etl/bucket.git", - "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-etl/bucket/zipball/8b3f318398ceaca1fb25154ff8a06adf175b1c31", - "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31", - "shasum": "" - }, - "require": { - "php": "^8.2", - "php-etl/bucket-contracts": "0.3.*" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.38", - "phpspec/phpspec": "^7.3", - "phpstan/phpstan": "^1.10", - "rector/rector": "^0.15" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.4.x-dev" - } - }, - "autoload": { - "psr-4": { - "Kiboko\\Component\\Bucket\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kiboko SAS", - "homepage": "http://kiboko.fr" - }, - { - "name": "Grégory Planchat", - "email": "gregory@kiboko.fr" - } - ], - "description": "This library implements the Extract-Transform-Load pattern asynchronously in PHP with the help of iterators and generators", - "support": { - "issues": "https://github.com/php-etl/bucket/issues", - "source": "https://github.com/php-etl/bucket/tree/v0.4.0" - }, - "time": "2023-11-16T15:32:18+00:00" - }, - { - "name": "php-etl/bucket-contracts", - "version": "v0.3.0", - "source": { - "type": "git", - "url": "https://github.com/php-etl/bucket-contracts.git", - "reference": "64170754cb1f5e556c8e526177be51d905c3b15f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/64170754cb1f5e556c8e526177be51d905c3b15f", - "reference": "64170754cb1f5e556c8e526177be51d905c3b15f", - "shasum": "" - }, - "require": { - "php": "^8.2" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "phpstan/phpstan": "^1.10", - "rector/rector": "^0.15" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Kiboko\\Contract\\Bucket\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kiboko SAS", - "homepage": "http://kiboko.fr" - }, - { - "name": "Grégory Planchatn rules", - "email": "gregory@kiboko.fr" - } - ], - "description": "This library describes contracts for the data-interchange buckets.", - "support": { - "issues": "https://github.com/php-etl/bucket-contracts/issues", - "source": "https://github.com/php-etl/bucket-contracts/tree/v0.3.0" - }, - "time": "2023-11-14T14:39:36+00:00" - }, { "name": "php-etl/configurator-contracts", "version": "v0.8.0", @@ -3506,6 +3396,116 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-etl/bucket", + "version": "v0.4.0", + "source": { + "type": "git", + "url": "https://github.com/php-etl/bucket.git", + "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-etl/bucket/zipball/8b3f318398ceaca1fb25154ff8a06adf175b1c31", + "reference": "8b3f318398ceaca1fb25154ff8a06adf175b1c31", + "shasum": "" + }, + "require": { + "php": "^8.2", + "php-etl/bucket-contracts": "0.3.*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.38", + "phpspec/phpspec": "^7.3", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.15" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Kiboko\\Component\\Bucket\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kiboko SAS", + "homepage": "http://kiboko.fr" + }, + { + "name": "Grégory Planchat", + "email": "gregory@kiboko.fr" + } + ], + "description": "This library implements the Extract-Transform-Load pattern asynchronously in PHP with the help of iterators and generators", + "support": { + "issues": "https://github.com/php-etl/bucket/issues", + "source": "https://github.com/php-etl/bucket/tree/v0.4.0" + }, + "time": "2023-11-16T15:32:18+00:00" + }, + { + "name": "php-etl/bucket-contracts", + "version": "v0.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-etl/bucket-contracts.git", + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/64170754cb1f5e556c8e526177be51d905c3b15f", + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f", + "shasum": "" + }, + "require": { + "php": "^8.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", + "rector/rector": "^0.15" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Kiboko\\Contract\\Bucket\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kiboko SAS", + "homepage": "http://kiboko.fr" + }, + { + "name": "Grégory Planchatn rules", + "email": "gregory@kiboko.fr" + } + ], + "description": "This library describes contracts for the data-interchange buckets.", + "support": { + "issues": "https://github.com/php-etl/bucket-contracts/issues", + "source": "https://github.com/php-etl/bucket-contracts/tree/v0.3.0" + }, + "time": "2023-11-14T14:39:36+00:00" + }, { "name": "php-etl/phpunit-extension", "version": "dev-main", From 563ae0b91752749c2d64ba609e17d421a3b7e9ce Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 12 Jan 2024 10:30:21 +0100 Subject: [PATCH 8/9] Added more tests for the object mapper + renamed functions --- tests/functional/Builder/ArrayMapperTest.php | 4 +- tests/functional/Builder/DTO/Product.php | 14 ++++++ tests/functional/Builder/ObjectMapperTest.php | 46 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/functional/Builder/DTO/Product.php create mode 100644 tests/functional/Builder/ObjectMapperTest.php diff --git a/tests/functional/Builder/ArrayMapperTest.php b/tests/functional/Builder/ArrayMapperTest.php index 23f24c4..9f44a0e 100644 --- a/tests/functional/Builder/ArrayMapperTest.php +++ b/tests/functional/Builder/ArrayMapperTest.php @@ -16,7 +16,7 @@ final class ArrayMapperTest extends BuilderTestCase { use TransformerBuilderAssertTrait; - public function testWithOneConditionThatMatch() + public function testWithASingleCopyField() { $builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper( $mapper = new ArrayBuilder() @@ -42,7 +42,7 @@ public function testWithOneConditionThatMatch() ); } - public function testWithSeveralConditionsThatMatch() + public function testWithSameNumberOfOutputFields() { $builder = new \Kiboko\Plugin\FastMap\Builder\ArrayMapper( $mapper = new ArrayBuilder() diff --git a/tests/functional/Builder/DTO/Product.php b/tests/functional/Builder/DTO/Product.php new file mode 100644 index 0000000..5b061b3 --- /dev/null +++ b/tests/functional/Builder/DTO/Product.php @@ -0,0 +1,14 @@ +arguments('input.id', 'input.enabled'); + + $builder = new Transformer($builder); + + $this->assertBuildsTransformerTransformsLike( + [ + new Product(1) + ], + [ + new Product(1) + ], + $builder, + ); + + $this->assertBuildsTransformerTransformsLike( + [ + new Product(1, true) + ], + [ + new Product(1, true) + ], + $builder, + ); + } +} From 51822e792805f7e38545246f9bc2ee8e7e8abbee Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 12 Jan 2024 10:50:54 +0100 Subject: [PATCH 9/9] Removed unused methods --- tests/functional/Builder/BuilderTestCase.php | 42 -------------------- 1 file changed, 42 deletions(-) diff --git a/tests/functional/Builder/BuilderTestCase.php b/tests/functional/Builder/BuilderTestCase.php index 2a0606c..393f8a9 100644 --- a/tests/functional/Builder/BuilderTestCase.php +++ b/tests/functional/Builder/BuilderTestCase.php @@ -35,46 +35,4 @@ public function pipelineRunner(): PipelineRunnerInterface { return new PipelineRunner(); } - - protected function assertNodeIsInstanceOf(string $expected, DefaultBuilder $builder, string $message = ''): void - { - $printer = new PrettyPrinter\Standard(); - - try { - $filename = sha1(random_bytes(128)) .'.php'; - $file = new vfsStreamFile($filename); - $file->setContent($printer->prettyPrintFile([ - new Node\Stmt\Return_($builder->getNode()), - ])); - $this->fs->addChild($file); - - $actual = include vfsStream::url('root/'.$filename); - } catch (\ParseError $exception) { - echo $printer->prettyPrintFile([$builder->getNode()]); - $this->fail($exception->getMessage()); - } - - $this->assertInstanceOf($expected, $actual, $message); - } - - protected function assertNodeIsNotInstanceOf(string $expected, DefaultBuilder $builder, string $message = ''): void - { - $printer = new PrettyPrinter\Standard(); - - try { - $filename = sha1(random_bytes(128)) .'.php'; - $file = new vfsStreamFile($filename); - $file->setContent($printer->prettyPrintFile([ - new Node\Stmt\Return_($builder->getNode()), - ])); - $this->fs->addChild($file); - - $actual = include vfsStream::url('root/'.$filename); - } catch (\ParseError $exception) { - echo $printer->prettyPrintFile([$builder->getNode()]); - $this->fail($exception->getMessage()); - } - - $this->assertNotInstanceOf($expected, $actual, $message); - } }