Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests #6

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor/
composer.lock
/.phpunit.result.cache
/.phpunit.cache
28 changes: 28 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="false"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
convertWarningsToExceptions="false"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/FieldConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
16 changes: 9 additions & 7 deletions tests/Foo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%';
}
}
28 changes: 23 additions & 5 deletions tests/ParsingTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

use Mamazu\ConfigConverter\ClassConfigConverter;
use Sylius\Component\Grid\Definition\ArrayToDefinitionConverter;
use Symfony\Component\Yaml\Yaml;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

class ParsingTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -15,28 +17,44 @@ 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__);
}
}
}

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);
}
}
42 changes: 15 additions & 27 deletions tests/SyliusAdminOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
])
)
Expand All @@ -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',
],
Expand All @@ -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',
],
Expand All @@ -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',
],
Expand All @@ -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')
Expand Down Expand Up @@ -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%';
}
}