From 3bb279fcfd30fc3fb1e5a353f53a75f6b0092a4b Mon Sep 17 00:00:00 2001 From: jb cr <51637606+jbcr@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:13:59 +0100 Subject: [PATCH] fix tests --- .gitignore | 2 ++ phpunit.xml.dist | 28 +++++++++++++++++++++++++ src/FieldConverter.php | 2 +- tests/Foo.php | 16 ++++++++------- tests/ParsingTest.php | 28 ++++++++++++++++++++----- tests/SyliusAdminOrder.php | 42 ++++++++++++++------------------------ 6 files changed, 78 insertions(+), 40 deletions(-) create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index d1502b0..b7ae51b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor/ composer.lock +/.phpunit.result.cache +/.phpunit.cache diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3482ef2 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,28 @@ + + + + + tests + + + + + + src + + + 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..0ab8eea 100644 --- a/tests/ParsingTest.php +++ b/tests/ParsingTest.php @@ -1,7 +1,9 @@ getExtension(), ['yaml', 'yml'])) { - $builder->convert($file->getFilename()); + $builder->convert($file->getFilename(), __DIR__); } } } - public function testConfigurationForOrder() { + /** @covers */ + public function testConfigurationForOrder() + { $yaml = Yaml::parse(file_get_contents('order.yml'))['sylius_grid']['grids']['sylius_admin_order']; $this->compileFile(); include 'SyliusAdminOrder.php'; $orderGrid = new \SyliusAdminOrder(); - $this->assertEquals($yaml, $orderGrid->toArray()); + $edi = $this->createMock(EventDispatcherInterface::class); + $converter = new ArrayToDefinitionConverter($edi); + + $def1 = $converter->convert('sylius_admin_order', $yaml); + $def2 = $converter->convert('sylius_admin_order', $orderGrid->toArray()); + + $this->assertEquals($def1, $def2); } - public function testConfigurationForAdvancedConfig() { + /** @covers */ + public function testConfigurationForAdvancedConfig() + { $yaml = Yaml::parse(file_get_contents('advanced_configuration.yml'))['sylius_grid']['grids']['foo']; $this->compileFile(); include 'Foo.php'; $orderGrid = new \Foo(); - $this->assertEquals($yaml, $orderGrid->toArray()); + $edi = $this->createMock(EventDispatcherInterface::class); + $converter = new ArrayToDefinitionConverter($edi); + + $def1 = $converter->convert('foo', $yaml); + $def2 = $converter->convert('foo', $orderGrid->toArray()); + + $this->assertEquals($def1, $def2); } } diff --git a/tests/SyliusAdminOrder.php b/tests/SyliusAdminOrder.php index 3aee307..d31b5e6 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') @@ -180,8 +163,13 @@ public function buildGrid(GridBuilderInterface $gridBuilder) : void ]) ) ->addActionGroup( - ItemActionGroup::create(ShowAction::create()) + ItemActionGroup::create(ShowAction::create() + ->setLabel('sylius.ui.show')) ) ; } + public function getResourceClass() : string + { + return '%sylius.model.order.class%'; + } }