From e977276dd4b5f53645ac125abc75d9fcd884a01c Mon Sep 17 00:00:00 2001 From: jb cr <51637606+jbcr@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:02:05 +0100 Subject: [PATCH] update dependencies and try fix test --- .gitignore | 1 + composer.json | 4 ++-- phpunit.xml | 28 ++++++++++++++++++++++++ src/ClassConfigConverter.php | 9 ++++++-- src/FieldConverter.php | 2 +- tests/Foo.php | 16 ++++++++------ tests/ParsingTest.php | 2 +- tests/SyliusAdminOrder.php | 42 +++++++++++------------------------- 8 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index d1502b0..d0757eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ composer.lock +.phpunit.cache/ diff --git a/composer.json b/composer.json index 42d61a9..b746e0c 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "require": { "php": ">=7.4", "symplify/php-config-printer": "^9.4.70", - "symfony/yaml": "^v5.4.14", - "sylius/grid-bundle": "1.12.x-dev", + "symfony/yaml": "^5.4|^6.4", + "sylius/grid-bundle": "1.12.x-dev|1.13.x-dev", "phpunit/phpunit": "^9.5.26" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..2fe8ddc --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,28 @@ + + + + + tests + + + + + + src + + + diff --git a/src/ClassConfigConverter.php b/src/ClassConfigConverter.php index 6beff6e..26d7d75 100644 --- a/src/ClassConfigConverter.php +++ b/src/ClassConfigConverter.php @@ -70,6 +70,11 @@ public function makeQuiet(): void public function convert(string $fileName, string $outputDirectory): void { + $outputDirectory = realpath($outputDirectory); + if ($outputDirectory === false) { + throw new InvalidArgumentException('Invalid output directory: '.$outputDirectory); + } + $allGrids = Yaml::parse(file_get_contents($fileName))['sylius_grid']['grids'] ?? []; if (!is_array($allGrids)) { @@ -90,13 +95,13 @@ public function convert(string $fileName, string $outputDirectory): void try { [$className, $phpCode] = $this->handleGrid($gridName, $gridConfiguration); } catch (\Throwable $e) { - printf('EXCEPTION "%s" on grid "%s": %s', get_class($e), $gridName, $e->getMessage()); + printf('EXCEPTION "%s" on grid "%s": %s%s', get_class($e), $gridName, $e->getMessage(), PHP_EOL); continue; } $new_content = $this->codeOutputter->printCode($phpCode); $newFileName = $className . '.php'; - $newFilePath = realpath($outputDirectory . DIRECTORY_SEPARATOR . $newFileName); + $newFilePath = $outputDirectory. DIRECTORY_SEPARATOR . $newFileName; if ($this->verbose) { echo "==============================$newFilePath================" . PHP_EOL; echo $new_content; diff --git a/src/FieldConverter.php b/src/FieldConverter.php index 56273b2..bcfb759 100644 --- a/src/FieldConverter.php +++ b/src/FieldConverter.php @@ -49,7 +49,7 @@ public function convertField(Expr $gridBuilder, string $fieldName, array $fieldC if (isset($fieldConfig['options'])) { unset($fieldConfig['options']['template']); if (count($fieldConfig['options']) > 0) { - $field = new MethodCall($field, 'setOptions', [$this->convertValue($fieldConfig['options'])]); + $field = new MethodCall($field, 'addOptions', [$this->convertValue($fieldConfig['options'])]); } unset($fieldConfig['options']); } diff --git a/tests/Foo.php b/tests/Foo.php index 9d597f1..d6f7515 100644 --- a/tests/Foo.php +++ b/tests/Foo.php @@ -3,41 +3,43 @@ * This code is generated by the config converter under https://github.com/mamazu/grid-config-converter * Feel free to modify the code as you see fit. */ +declare (strict_types=1); use Sylius\Bundle\GridBundle\Grid\AbstractGrid; use Sylius\Bundle\GridBundle\Builder\Filter\Filter; use Sylius\Bundle\GridBundle\Builder\Field\Field; use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface; use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup; use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup; +use Sylius\Bundle\GridBundle\Builder\ActionGroup\SubItemActionGroup; use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup; use Sylius\Bundle\GridBundle\Config\GridConfig; use Sylius\Bundle\GridBundle\Builder\GridBuilder; use Sylius\Bundle\GridBundle\Builder\Action\Action; use Sylius\Bundle\GridBundle\Builder\Action\ShowAction; +use Sylius\Bundle\GridBundle\Builder\Action\CreateAction; use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction; use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction; use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField; use Sylius\Bundle\GridBundle\Builder\Field\StringField; use Sylius\Bundle\GridBundle\Builder\Field\TwigField; -class Foo extends AbstractGrid +use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface; +class Foo extends AbstractGrid implements ResourceAwareGridInterface { public static function getName() : string { return 'foo'; } - public static function getResourceClass() : string - { - return '%sylius.model.order.class%'; - } public function buildGrid(GridBuilderInterface $gridBuilder) : void { $gridBuilder - ->setDriver('doctrine/orm') - ->setDriverOption('class', '%sylius.model.order.class%') ->setDriverOption('pagination', [ 'fetch_join_collection' => false, 'use_output_walkers' => false, ]) ; } + public function getResourceClass() : string + { + return '%sylius.model.order.class%'; + } } diff --git a/tests/ParsingTest.php b/tests/ParsingTest.php index 58d726d..eb3bb10 100644 --- a/tests/ParsingTest.php +++ b/tests/ParsingTest.php @@ -15,7 +15,7 @@ private function compileFile() { foreach(new DirectoryIterator('.') as $file) { /** @var DirectoryIterator $file */ if(in_array($file->getExtension(), ['yaml', 'yml'])) { - $builder->convert($file->getFilename()); + $builder->convert($file->getFilename(), __DIR__); } } } diff --git a/tests/SyliusAdminOrder.php b/tests/SyliusAdminOrder.php index 3aee307..d1967bb 100644 --- a/tests/SyliusAdminOrder.php +++ b/tests/SyliusAdminOrder.php @@ -3,40 +3,38 @@ * This code is generated by the config converter under https://github.com/mamazu/grid-config-converter * Feel free to modify the code as you see fit. */ +declare (strict_types=1); use Sylius\Bundle\GridBundle\Grid\AbstractGrid; use Sylius\Bundle\GridBundle\Builder\Filter\Filter; use Sylius\Bundle\GridBundle\Builder\Field\Field; use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface; use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup; use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup; +use Sylius\Bundle\GridBundle\Builder\ActionGroup\SubItemActionGroup; use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup; use Sylius\Bundle\GridBundle\Config\GridConfig; use Sylius\Bundle\GridBundle\Builder\GridBuilder; use Sylius\Bundle\GridBundle\Builder\Action\Action; use Sylius\Bundle\GridBundle\Builder\Action\ShowAction; +use Sylius\Bundle\GridBundle\Builder\Action\CreateAction; use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction; use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction; use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField; use Sylius\Bundle\GridBundle\Builder\Field\StringField; use Sylius\Bundle\GridBundle\Builder\Field\TwigField; -class SyliusAdminOrder extends AbstractGrid +use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface; +class SyliusAdminOrder extends AbstractGrid implements ResourceAwareGridInterface { public static function getName() : string { return 'sylius_admin_order'; } - public static function getResourceClass() : string - { - return '%sylius.model.order.class%'; - } public function buildGrid(GridBuilderInterface $gridBuilder) : void { $gridBuilder - ->setDriver('doctrine/orm') ->setRepositoryMethod('myCustomMethod', [ 'id' => 'resource.id', ]) - ->setDriverOption('class', '%sylius.model.order.class%') ->setDriverOption('pagination', [ 'fetch_join_collection' => false, 'use_output_walkers' => false, @@ -54,7 +52,7 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void ->setPosition(100) ->setPath('checkoutCompletedAt') ->setSortable(true, 'checkoutCompletedAt') - ->setOptions([ + ->addOptions([ 'format' => 'd-m-Y H:i:s', ]) ) @@ -63,32 +61,22 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void ->setLabel('sylius.ui.number') ->setPath('.') ->setSortable(true) - ->setOptions([ - 'template' => '@SyliusAdmin/Order/Grid/Field/number.html.twig', - ]) ) ->addField( TwigField::create('channel', '@SyliusAdmin/Order/Grid/Field/channel.html.twig') ->setLabel('sylius.ui.channel') ->setSortable(true, 'channel.code') - ->setOptions([ - 'template' => '@SyliusAdmin/Order/Grid/Field/channel.html.twig', - ]) ) ->addField( TwigField::create('customer', '@SyliusAdmin/Order/Grid/Field/customer.html.twig') ->setLabel('sylius.ui.customer') ->setSortable(true, 'customer.lastName') - ->setOptions([ - 'template' => '@SyliusAdmin/Order/Grid/Field/customer.html.twig', - ]) ) ->addField( TwigField::create('state', '@SyliusUi/Grid/Field/state.html.twig') ->setLabel('sylius.ui.state') ->setSortable(true) - ->setOptions([ - 'template' => '@SyliusUi/Grid/Field/state.html.twig', + ->addOptions([ 'vars' => [ 'labels' => '@SyliusAdmin/Order/Label/State', ], @@ -98,8 +86,7 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void TwigField::create('paymentState', '@SyliusUi/Grid/Field/state.html.twig') ->setLabel('sylius.ui.payment_state') ->setSortable(true) - ->setOptions([ - 'template' => '@SyliusUi/Grid/Field/state.html.twig', + ->addOptions([ 'vars' => [ 'labels' => '@SyliusAdmin/Order/Label/PaymentState', ], @@ -109,8 +96,7 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void TwigField::create('shippingState', '@SyliusUi/Grid/Field/state.html.twig') ->setLabel('sylius.ui.shipping_state') ->setSortable(true) - ->setOptions([ - 'template' => '@SyliusUi/Grid/Field/state.html.twig', + ->addOptions([ 'vars' => [ 'labels' => '@SyliusAdmin/Order/Label/ShippingState', ], @@ -121,9 +107,6 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void ->setLabel('sylius.ui.total') ->setPath('.') ->setSortable(true, 'total') - ->setOptions([ - 'template' => '@SyliusAdmin/Order/Grid/Field/total.html.twig', - ]) ) ->addField( StringField::create('currencyCode') @@ -179,9 +162,10 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void 'class' => '%sylius.model.shipping_method.class%', ]) ) - ->addActionGroup( - ItemActionGroup::create(ShowAction::create()) - ) ; } + public function getResourceClass() : string + { + return '%sylius.model.order.class%'; + } }