Skip to content

Commit

Permalink
[BootstrapAdminUi] Add functional tests & fix requirements (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 authored Sep 24, 2024
2 parents 10fc3c9 + 4da7a93 commit bc0d101
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 9 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions src/AdminUi/tests/Functional/.application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ APP_ENV=dev
APP_SECRET=c9570eaa5cbfadf33ad1a93f95c2e42a
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
###< doctrine/doctrine-bundle ###
32 changes: 27 additions & 5 deletions src/BootstrapAdminUi/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
"type": "library",
"require": {
"php": "^8.1",
"pagerfanta/twig": "^4.6",
"sylius/admin-ui": "dev-main",
"sylius/grid-bundle": "^1.13@alpha",
"sylius/resource-bundle": "^1.11 || ^1.12@alpha",
"sylius/twig-extra": "dev-main",
"sylius/twig-hooks": "^0.3",
"symfony/asset": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/ux-live-component": "^2.17"
},
"require-dev": {
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/orm": "^2.0",
"phpunit/phpunit": "^9.6",
"symfony/dotenv": "^6.4 || ^7.0"
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/dotenv": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/runtime": "^6.4 || ^7.0",
"symfony/yaml": "^6.4 || ^7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -22,15 +32,27 @@
},
"autoload-dev": {
"psr-4": {
"TestApplication\\Sylius\\BootstrapAdminUi\\": "tests/Functional/.application/src/"
"TestApplication\\Sylius\\BootstrapAdminUi\\": "tests/Functional/.application/src/",
"Tests\\Sylius\\BootstrapAdminUi\\": "tests/"
}
},
"config": {
"allow-plugins": {
"symfony/runtime": true
},
"sort-packages": true
},
"repositories": [
{
"type": "path",
"url": "../*/*"
}
],
"extra": {
"symfony": {
"require": "7.1.*"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
4 changes: 4 additions & 0 deletions src/BootstrapAdminUi/tests/Functional/.application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
APP_ENV=dev
APP_SECRET=c9570eaa5cbfadf33ad1a93f95c2e42a
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
###< doctrine/doctrine-bundle ###
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
declare(strict_types=1);

return [
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Sylius\TwigHooks\TwigHooksBundle::class => ['all' => true],
Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true],
Sylius\BootstrapAdminUi\Symfony\SyliusBootstrapAdminUiBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\SyliusTwigExtraBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
Sylius\AdminUi\Symfony\SyliusAdminUiBundle::class => ['all' => true],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'

# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '16'

profiling_collect_backtrace: '%kernel.debug%'
use_savepoints: true
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
type: attribute
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App

when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
- { resource: '../../../../../config/app.php' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @see https://github.com/Sylius/SyliusResourceBundle/blob/master/docs/index.md
sylius_resource:
drivers: []

# Override default settings
#settings:

# Configure the mapping for your resources
mapping:
paths:
- '%kernel.project_dir%/src/Resource'

# Configure your resources
resources:
#app.book:
#classes:
#model: App\Entity\Book
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sylius_crud_routes:
resource: 'sylius.routing.loader.crud_routes_attributes'
type: service

sylius_routes:
resource: 'sylius.routing.loader.routes_attributes'
type: service
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
locale: en

services:
# default configuration for services in *this* file
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TestApplication\Sylius\BootstrapAdminUi\Resource\BookResource;

final class BookResourceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => BookResource::class,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\Grid;

use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup;
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;
use TestApplication\Sylius\BootstrapAdminUi\Grid\Provider\BookGridProvider;
use TestApplication\Sylius\BootstrapAdminUi\Resource\BookResource;

final class BookGrid extends AbstractGrid implements ResourceAwareGridInterface
{
public static function getName(): string
{
return 'app_book';
}

public function buildGrid(GridBuilderInterface $gridBuilder): void
{
$gridBuilder
->setProvider(BookGridProvider::class)
->addField(
StringField::create('name')
->setLabel('Name'),
)
->addActionGroup(
MainActionGroup::create(
CreateAction::create(),
),
)
->addActionGroup(
ItemActionGroup::create(
UpdateAction::create(),
),
)
;
}

public function getResourceClass(): string
{
return BookResource::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\Grid\Provider;

use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Sylius\Component\Grid\Data\DataProviderInterface;
use Sylius\Component\Grid\Definition\Grid;
use Sylius\Component\Grid\Parameters;
use TestApplication\Sylius\BootstrapAdminUi\Resource\BookResource;

class BookGridProvider implements DataProviderInterface
{
public function getData(Grid $grid, Parameters $parameters): Pagerfanta
{
return new Pagerfanta(new ArrayAdapter([
new BookResource('shinning', 'Shinning'),
new BookResource('carrie', 'Carrie'),
]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\Resource;

use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Update;
use Sylius\Resource\Model\ResourceInterface;
use TestApplication\Sylius\BootstrapAdminUi\Form\BookResourceType;
use TestApplication\Sylius\BootstrapAdminUi\Grid\BookGrid;
use TestApplication\Sylius\BootstrapAdminUi\State\Provider\BookItemProvider;

#[AsResource(
formType: BookResourceType::class,
templatesDir: '@SyliusAdminUi/crud',
driver: false,
operations: [
new Index(grid: BookGrid::class),
new Create(),
new Update(provider: BookItemProvider::class),
],
)]
final class BookResource implements ResourceInterface
{
public function __construct(
public ?string $id = null,
public ?string $name = null,
) {
}

public function getId(): ?string
{
return $this->id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace TestApplication\Sylius\BootstrapAdminUi\State\Provider;

use Sylius\Resource\Context\Context;
use Sylius\Resource\Metadata\Operation;
use Sylius\Resource\State\ProviderInterface;
use TestApplication\Sylius\BootstrapAdminUi\Resource\BookResource;

class BookItemProvider implements ProviderInterface
{
public function provide(Operation $operation, Context $context): BookResource
{
return new BookResource('shinning', 'Shinning');
}
}
Loading

0 comments on commit bc0d101

Please sign in to comment.