From e725de46edef81eeae15cc5c0aad5a7519586268 Mon Sep 17 00:00:00 2001 From: Pierre Ducoudray Date: Mon, 16 Jan 2017 15:14:37 +0100 Subject: [PATCH] Make bundle works with symfony 3 --- Controller/ReportController.php | 7 +- DataFetcher/NumberOfOrdersDataFetcher.php | 50 ++++++++++++++ DataFetcher/SalesTotalDataFetcher.php | 50 ++++++++++++++ DataFetcher/TimePeriod.php | 6 +- DataFetcher/UserRegistrationDataFetcher.php | 50 ++++++++++++++ .../Compiler/RegisterDataFetcherPass.php | 2 +- .../Compiler/RegisterRenderersPass.php | 2 +- DependencyInjection/Configuration.php | 7 +- Doctrine/ORM/OrderRepositoryInterface.php | 20 ++++++ Doctrine/ORM/UserRepositoryInterface.php | 13 ++++ .../DataFetcher/DataFetcherChoiceType.php | 55 ++++++++++++++++ Form/Type/DataFetcher/NumberOfOrdersType.php | 49 ++++++++++++++ Form/Type/DataFetcher/SalesTotalType.php | 49 ++++++++++++++ .../Type/DataFetcher/UserRegistrationType.php | 53 +++++++++++++++ Form/Type/Renderer/ChartConfigurationType.php | 15 ++--- Form/Type/Renderer/RendererChoiceType.php | 11 +--- Form/Type/Renderer/TableConfigurationType.php | 13 +--- Form/Type/ReportType.php | 20 +++--- Renderer/ChartRenderer.php | 4 +- Renderer/TableRenderer.php | 4 +- Resources/config/services.xml | 65 +++++++++++-------- Resources/{public => private}/js/chart.js | 0 .../js/prototype-handler.js | 0 .../{public => private}/js/sylius-report.js | 0 Resources/views/Table/macros.html.twig | 6 +- .../Compiler/RegisterDataFetcherPassSpec.php | 10 +-- .../Compiler/RegisterRenderersPassSpec.php | 10 +-- ...ildReportDataFetcherFormSubscriberSpec.php | 15 +++-- .../BuildReportRendererFormSubscriberSpec.php | 15 +++-- .../Renderer/ChartConfigurationTypeSpec.php | 19 +++--- .../Type/Renderer/RendererChoiceTypeSpec.php | 21 +++--- .../Renderer/TableConfigurationTypeSpec.php | 17 ++--- spec/Form/Type/ReportTypeSpec.php | 30 ++++----- spec/Renderer/ChartRendererSpec.php | 17 ++--- spec/Renderer/TableRendererSpec.php | 17 ++--- 35 files changed, 543 insertions(+), 179 deletions(-) create mode 100644 DataFetcher/NumberOfOrdersDataFetcher.php create mode 100644 DataFetcher/SalesTotalDataFetcher.php create mode 100644 DataFetcher/UserRegistrationDataFetcher.php create mode 100644 Doctrine/ORM/OrderRepositoryInterface.php create mode 100644 Doctrine/ORM/UserRepositoryInterface.php create mode 100644 Form/Type/DataFetcher/DataFetcherChoiceType.php create mode 100644 Form/Type/DataFetcher/NumberOfOrdersType.php create mode 100644 Form/Type/DataFetcher/SalesTotalType.php create mode 100644 Form/Type/DataFetcher/UserRegistrationType.php rename Resources/{public => private}/js/chart.js (100%) rename Resources/{public => private}/js/prototype-handler.js (100%) rename Resources/{public => private}/js/sylius-report.js (100%) diff --git a/Controller/ReportController.php b/Controller/ReportController.php index be13f5a..110e784 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -37,7 +37,8 @@ public function renderAction(Request $request) $report = $this->findOr404($configuration); - $formType = $report->getDataFetcher(); + $dataFetcher = $this->get($report->getDataFetcher()); + $formType = $dataFetcher->getType(); $configurationForm = $this->container->get('form.factory')->createNamed( 'configuration', $formType, @@ -45,7 +46,7 @@ public function renderAction(Request $request) ); if ($request->query->has('configuration')) { - $configurationForm->submit($request); + $configurationForm->submit($request->request->get($configurationForm->getName())); } return $this->container->get('templating')->renderResponse($configuration->getTemplate('show.html'), [ @@ -75,7 +76,7 @@ public function embedAction(Request $request, $report, array $configuration = [] } $configuration = ($request->query->has('configuration')) ? $request->query->get('configuration', $configuration) : $report->getDataFetcherConfiguration(); - $configuration['baseCurrency'] = $currencyProvider->getBaseCurrency(); + $configuration['baseCurrency'] = $currencyProvider->getDefaultCurrencyCode(); $data = $this->getReportDataFetcher()->fetch($report, $configuration); diff --git a/DataFetcher/NumberOfOrdersDataFetcher.php b/DataFetcher/NumberOfOrdersDataFetcher.php new file mode 100644 index 0000000..1ba9844 --- /dev/null +++ b/DataFetcher/NumberOfOrdersDataFetcher.php @@ -0,0 +1,50 @@ + + */ +class NumberOfOrdersDataFetcher extends TimePeriod +{ + /** + * @var OrderRepositoryInterface + */ + protected $orderRepository; + + /** + * @param OrderRepositoryInterface $orderRepository + */ + public function __construct(OrderRepositoryInterface $orderRepository) + { + $this->orderRepository = $orderRepository; + } + + /** + * {@inheritdoc} + */ + protected function getData(array $configuration = []) + { + return $this->orderRepository->ordersBetweenDatesGroupByDate($configuration); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return NumberOfOrdersType::class; + } +} diff --git a/DataFetcher/SalesTotalDataFetcher.php b/DataFetcher/SalesTotalDataFetcher.php new file mode 100644 index 0000000..cb62fdc --- /dev/null +++ b/DataFetcher/SalesTotalDataFetcher.php @@ -0,0 +1,50 @@ + + */ +class SalesTotalDataFetcher extends TimePeriod +{ + /** + * @var OrderRepositoryInterface + */ + protected $orderRepository; + + /** + * @param OrderRepositoryInterface $orderRepository + */ + public function __construct(OrderRepositoryInterface $orderRepository) + { + $this->orderRepository = $orderRepository; + } + + /** + * {@inheritdoc} + */ + protected function getData(array $configuration = []) + { + return $this->orderRepository->revenueBetweenDatesGroupByDate($configuration); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return SalesTotalType::class; + } +} diff --git a/DataFetcher/TimePeriod.php b/DataFetcher/TimePeriod.php index 9fee80f..8c09045 100644 --- a/DataFetcher/TimePeriod.php +++ b/DataFetcher/TimePeriod.php @@ -31,9 +31,9 @@ abstract class TimePeriod implements DataFetcherInterface public static function getPeriodChoices() { return [ - self::PERIOD_DAY => 'Daily', - self::PERIOD_MONTH => 'Monthly', - self::PERIOD_YEAR => 'Yearly', + 'Daily' => self::PERIOD_DAY, + 'Monthly' => self::PERIOD_MONTH, + 'Yearly' => self::PERIOD_YEAR, ]; } diff --git a/DataFetcher/UserRegistrationDataFetcher.php b/DataFetcher/UserRegistrationDataFetcher.php new file mode 100644 index 0000000..a125c48 --- /dev/null +++ b/DataFetcher/UserRegistrationDataFetcher.php @@ -0,0 +1,50 @@ + + */ +class UserRegistrationDataFetcher extends TimePeriod +{ + /** + * @var UserRepositoryInterface + */ + protected $userRepository; + + /** + * @param UserRepositoryInterface $userRepository + */ + public function __construct(UserRepositoryInterface $userRepository) + { + $this->userRepository = $userRepository; + } + + /** + * {@inheritdoc} + */ + protected function getData(array $configuration = []) + { + return $this->userRepository->getRegistrationStatistic($configuration); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return UserRegistrationType::class; + } +} diff --git a/DependencyInjection/Compiler/RegisterDataFetcherPass.php b/DependencyInjection/Compiler/RegisterDataFetcherPass.php index da66b8e..f71582e 100644 --- a/DependencyInjection/Compiler/RegisterDataFetcherPass.php +++ b/DependencyInjection/Compiler/RegisterDataFetcherPass.php @@ -43,7 +43,7 @@ public function process(ContainerBuilder $container) } $name = $attributes[0]['fetcher']; - $dataFetchers[$name] = $attributes[0]['label']; + $dataFetchers[$attributes[0]['label']] = $name; $registry->addMethodCall('register', [$name, new Reference($id)]); } diff --git a/DependencyInjection/Compiler/RegisterRenderersPass.php b/DependencyInjection/Compiler/RegisterRenderersPass.php index a4b5480..c871ff8 100644 --- a/DependencyInjection/Compiler/RegisterRenderersPass.php +++ b/DependencyInjection/Compiler/RegisterRenderersPass.php @@ -41,7 +41,7 @@ public function process(ContainerBuilder $container) } $name = $attributes[0]['renderer']; - $renderers[$name] = $attributes[0]['label']; + $renderers[$attributes[0]['label']] = $name; $registry->addMethodCall('register', [$name, new Reference($id)]); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1835f35..231778c 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -73,12 +73,7 @@ private function addResourcesSection(ArrayNodeDefinition $node) ->scalarNode('controller')->defaultValue(ReportController::class)->cannotBeEmpty()->end() ->scalarNode('repository')->cannotBeEmpty()->end() ->scalarNode('factory')->defaultValue(Factory::class)->end() - ->arrayNode('form') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('default')->defaultValue(ReportType::class)->cannotBeEmpty()->end() - ->end() - ->end() + ->scalarNode('form')->defaultValue(ReportType::class)->end() ->end() ->end() ->arrayNode('validation_groups') diff --git a/Doctrine/ORM/OrderRepositoryInterface.php b/Doctrine/ORM/OrderRepositoryInterface.php new file mode 100644 index 0000000..96c7a7b --- /dev/null +++ b/Doctrine/ORM/OrderRepositoryInterface.php @@ -0,0 +1,20 @@ + + */ +class DataFetcherChoiceType extends AbstractType +{ + /** + * @var array + */ + protected $dataFetchers; + + /** + * @param array $dataFetchers + */ + public function __construct($dataFetchers) + { + $this->dataFetchers = $dataFetchers; + } + + /** + * {@inheritdoc} + */ + public function configureOptions(OptionsResolver $resolver) + { + $resolver + ->setDefaults([ + 'choices' => $this->dataFetchers, + ]) + ; + } + + /** + * {@inheritdoc} + */ + public function getParent() + { + return ChoiceType::class; + } +} diff --git a/Form/Type/DataFetcher/NumberOfOrdersType.php b/Form/Type/DataFetcher/NumberOfOrdersType.php new file mode 100644 index 0000000..849b5bc --- /dev/null +++ b/Form/Type/DataFetcher/NumberOfOrdersType.php @@ -0,0 +1,49 @@ + + */ +class NumberOfOrdersType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('start', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.start', + ]) + ->add('end', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.end', + ]) + ->add('period', ChoiceType::class, [ + 'choices' => NumberOfOrdersDataFetcher::getPeriodChoices(), + 'multiple' => false, + 'label' => 'sylius.form.report.user_registration.period', + ]) + ->add('empty_records', CheckboxType::class, [ + 'label' => 'sylius.form.report.user_registration.empty_records', + 'required' => false, + ]) + ; + } +} diff --git a/Form/Type/DataFetcher/SalesTotalType.php b/Form/Type/DataFetcher/SalesTotalType.php new file mode 100644 index 0000000..b1c0bcf --- /dev/null +++ b/Form/Type/DataFetcher/SalesTotalType.php @@ -0,0 +1,49 @@ + + */ +class SalesTotalType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('start', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.start', + ]) + ->add('end', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.end', + ]) + ->add('period', ChoiceType::class, [ + 'choices' => SalesTotalDataFetcher::getPeriodChoices(), + 'multiple' => false, + 'label' => 'sylius.form.report.user_registration.period', + ]) + ->add('empty_records', CheckboxType::class, [ + 'label' => 'sylius.form.report.user_registration.empty_records', + 'required' => false, + ]) + ; + } +} diff --git a/Form/Type/DataFetcher/UserRegistrationType.php b/Form/Type/DataFetcher/UserRegistrationType.php new file mode 100644 index 0000000..5eec3c0 --- /dev/null +++ b/Form/Type/DataFetcher/UserRegistrationType.php @@ -0,0 +1,53 @@ + + */ +class UserRegistrationType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('start', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.start', + 'years' => range(date('Y') - 100, date('Y')), + 'data' => new \DateTime(), + ]) + ->add('end', DateType::class, [ + 'label' => 'sylius.form.report.user_registration.end', + 'years' => range(date('Y') - 100, date('Y')), + 'data' => new \DateTime(), + ]) + ->add('period', ChoiceType::class, [ + 'choices' => UserRegistrationDataFetcher::getPeriodChoices(), + 'multiple' => false, + 'label' => 'sylius.form.report.user_registration.period', + ]) + ->add('empty_records', CheckboxType::class, [ + 'label' => 'sylius.form.report.user_registration.empty_records', + 'required' => false, + ]) + ; + } +} diff --git a/Form/Type/Renderer/ChartConfigurationType.php b/Form/Type/Renderer/ChartConfigurationType.php index f5f8dff..a246f28 100644 --- a/Form/Type/Renderer/ChartConfigurationType.php +++ b/Form/Type/Renderer/ChartConfigurationType.php @@ -13,6 +13,7 @@ use Sylius\Bundle\ReportBundle\Renderer\ChartRenderer; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; /** @@ -28,24 +29,16 @@ class ChartConfigurationType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('type', 'choice', [ + ->add('type', ChoiceType::class, [ 'label' => 'sylius.form.report.chart.type', 'choices' => ChartRenderer::getChartTypes(), ]) - ->add('template', 'choice', [ + ->add('template', ChoiceType::class, [ 'label' => 'sylius.form.report.renderer.template', 'choices' => [ - 'SyliusReportBundle:Chart:default.html.twig' => 'Default', + 'Default' => 'SyliusReportBundle:Chart:default.html.twig', ], ]) ; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_renderer_chart'; - } } diff --git a/Form/Type/Renderer/RendererChoiceType.php b/Form/Type/Renderer/RendererChoiceType.php index 5c0ec16..23c99e0 100644 --- a/Form/Type/Renderer/RendererChoiceType.php +++ b/Form/Type/Renderer/RendererChoiceType.php @@ -12,6 +12,7 @@ namespace Sylius\Bundle\ReportBundle\Form\Type\Renderer; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -48,14 +49,6 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return 'choice'; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_renderer_choice'; + return ChoiceType::class; } } diff --git a/Form/Type/Renderer/TableConfigurationType.php b/Form/Type/Renderer/TableConfigurationType.php index 5e6779f..f826405 100644 --- a/Form/Type/Renderer/TableConfigurationType.php +++ b/Form/Type/Renderer/TableConfigurationType.php @@ -12,6 +12,7 @@ namespace Sylius\Bundle\ReportBundle\Form\Type\Renderer; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; /** @@ -27,20 +28,12 @@ class TableConfigurationType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('template', 'choice', [ + ->add('template', ChoiceType::class, [ 'label' => 'sylius.form.report.renderer.template', 'choices' => [ - 'SyliusReportBundle:Table:default.html.twig' => 'Default', + 'Default' => 'SyliusReportBundle:Table:default.html.twig', ], ]) ; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_renderer_table'; - } } diff --git a/Form/Type/ReportType.php b/Form/Type/ReportType.php index d25b96f..aa64a5b 100644 --- a/Form/Type/ReportType.php +++ b/Form/Type/ReportType.php @@ -11,13 +11,17 @@ namespace Sylius\Bundle\ReportBundle\Form\Type; +use Sylius\Bundle\ReportBundle\Form\Type\DataFetcher\DataFetcherChoiceType; use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportDataFetcherFormSubscriber; use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportRendererFormSubscriber; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\RendererChoiceType; use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Report\DataFetcher\DataFetcherInterface; use Sylius\Component\Report\Renderer\RendererInterface; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; @@ -63,18 +67,18 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->addEventSubscriber(new AddCodeFormSubscriber()) ->addEventSubscriber(new BuildReportDataFetcherFormSubscriber($this->dataFetcherRegistry, $builder->getFormFactory())) ->addEventSubscriber(new BuildReportRendererFormSubscriber($this->rendererRegistry, $builder->getFormFactory())) - ->add('name', 'text', [ + ->add('name', TextType::class, [ 'label' => 'sylius.form.report.name', 'required' => true, ]) - ->add('description', 'textarea', [ + ->add('description', TextareaType::class, [ 'label' => 'sylius.form.report.description', 'required' => false, ]) - ->add('dataFetcher', 'sylius_data_fetcher_choice', [ + ->add('dataFetcher', DataFetcherChoiceType::class, [ 'label' => 'sylius.form.report.data_fetcher', ]) - ->add('renderer', 'sylius_renderer_choice', [ + ->add('renderer', RendererChoiceType::class, [ 'label' => 'sylius.form.report.renderer.label', ]) ; @@ -130,12 +134,4 @@ public function buildView(FormView $view, FormInterface $form, array $options) } } } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'sylius_report'; - } } diff --git a/Renderer/ChartRenderer.php b/Renderer/ChartRenderer.php index 6c9a15d..0741503 100644 --- a/Renderer/ChartRenderer.php +++ b/Renderer/ChartRenderer.php @@ -11,9 +11,9 @@ namespace Sylius\Bundle\ReportBundle\Renderer; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\ChartConfigurationType; use Sylius\Component\Report\DataFetcher\Data; use Sylius\Component\Report\Model\ReportInterface; -use Sylius\Component\Report\Renderer\DefaultRenderers; use Sylius\Component\Report\Renderer\RendererInterface; use Symfony\Component\Templating\EngineInterface; @@ -73,7 +73,7 @@ public function render(ReportInterface $report, Data $data) */ public function getType() { - return DefaultRenderers::CHART; + return ChartConfigurationType::class; } /** diff --git a/Renderer/TableRenderer.php b/Renderer/TableRenderer.php index 0fb410c..768ff35 100644 --- a/Renderer/TableRenderer.php +++ b/Renderer/TableRenderer.php @@ -11,9 +11,9 @@ namespace Sylius\Bundle\ReportBundle\Renderer; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\TableConfigurationType; use Sylius\Component\Report\DataFetcher\Data; use Sylius\Component\Report\Model\ReportInterface; -use Sylius\Component\Report\Renderer\DefaultRenderers; use Sylius\Component\Report\Renderer\RendererInterface; use Symfony\Component\Templating\EngineInterface; @@ -67,6 +67,6 @@ public function render(ReportInterface $report, Data $data) */ public function getType() { - return DefaultRenderers::TABLE; + return TableConfigurationType::class; } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index a3abbcc..3c2b444 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -16,73 +16,82 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - Sylius\Component\Registry\ServiceRegistry - - Sylius\Component\Report\DataFetcher\DelegatingDataFetcher - Sylius\Component\Report\Renderer\DelegatingRenderer - - Sylius\Bundle\CoreBundle\Form\Type\DataFetcher\DataFetcherChoiceType - Sylius\Bundle\ReportBundle\Renderer\ChartRenderer - Sylius\Bundle\ReportBundle\Renderer\TableRenderer - Sylius\Bundle\ReportBundle\Form\Type\Renderer\RendererChoiceType - Sylius\Bundle\ReportBundle\Form\Type\Renderer\ChartConfigurationType - Sylius\Bundle\ReportBundle\Form\Type\Renderer\TableConfigurationType - - - + Sylius\Component\Report\DataFetcher\DataFetcherInterface data fetcher - + Sylius\Component\Report\Renderer\RendererInterface report renderer - + - + + + + + + + + + + + + + + + + + + + - + %sylius.report.data_fetchers% - + - + - + - + %sylius.report.renderers% - + - - + + - - + + + + %sylius.model.report.class% + sylius + + diff --git a/Resources/public/js/chart.js b/Resources/private/js/chart.js similarity index 100% rename from Resources/public/js/chart.js rename to Resources/private/js/chart.js diff --git a/Resources/public/js/prototype-handler.js b/Resources/private/js/prototype-handler.js similarity index 100% rename from Resources/public/js/prototype-handler.js rename to Resources/private/js/prototype-handler.js diff --git a/Resources/public/js/sylius-report.js b/Resources/private/js/sylius-report.js similarity index 100% rename from Resources/public/js/sylius-report.js rename to Resources/private/js/sylius-report.js diff --git a/Resources/views/Table/macros.html.twig b/Resources/views/Table/macros.html.twig index 22f3c30..414f9cd 100644 --- a/Resources/views/Table/macros.html.twig +++ b/Resources/views/Table/macros.html.twig @@ -3,12 +3,12 @@ {% import 'SyliusResourceBundle:Macros:buttons.html.twig' as buttons %} {% if values|length > 0 %} - +
- + {% for label in labels %} - + {% endfor %} diff --git a/spec/DependencyInjection/Compiler/RegisterDataFetcherPassSpec.php b/spec/DependencyInjection/Compiler/RegisterDataFetcherPassSpec.php index 7c056f7..eb74208 100644 --- a/spec/DependencyInjection/Compiler/RegisterDataFetcherPassSpec.php +++ b/spec/DependencyInjection/Compiler/RegisterDataFetcherPassSpec.php @@ -22,12 +22,12 @@ */ final class RegisterDataFetcherPassSpec extends ObjectBehavior { - function it_should_implement_compiler_pass_interface() + public function it_should_implement_compiler_pass_interface() { $this->shouldImplement(CompilerPassInterface::class); } - function it_processes_with_given_container(ContainerBuilder $container, Definition $dataFetcherDefinition) + public function it_processes_with_given_container(ContainerBuilder $container, Definition $dataFetcherDefinition) { $container->hasDefinition('sylius.registry.report.data_fetcher')->willReturn(true); $container->getDefinition('sylius.registry.report.data_fetcher')->willReturn($dataFetcherDefinition); @@ -40,12 +40,12 @@ function it_processes_with_given_container(ContainerBuilder $container, Definiti $container->findTaggedServiceIds('sylius.report.data_fetcher')->willReturn($dataFetcherServices); $dataFetcherDefinition->addMethodCall('register', ['test', new Reference('sylius.form.type.data_fetcher.test')])->shouldBeCalled(); - $container->setParameter('sylius.report.data_fetchers', ['test' => 'Test data fetcher'])->shouldBeCalled(); + $container->setParameter('sylius.report.data_fetchers', ['Test data fetcher' => 'test'])->shouldBeCalled(); $this->process($container); } - function it_does_not_process_if_container_has_not_proper_definition(ContainerBuilder $container) + public function it_does_not_process_if_container_has_not_proper_definition(ContainerBuilder $container) { $container->hasDefinition('sylius.registry.report.data_fetcher')->willReturn(false); $container->getDefinition('sylius.registry.report.data_fetcher')->shouldNotBeCalled(); @@ -53,7 +53,7 @@ function it_does_not_process_if_container_has_not_proper_definition(ContainerBui $this->process($container); } - function it_throws_exception_if_any_data_fetcher_has_improper_attributes(ContainerBuilder $container, Definition $dataFetcherDefinition) + public function it_throws_exception_if_any_data_fetcher_has_improper_attributes(ContainerBuilder $container, Definition $dataFetcherDefinition) { $container->hasDefinition('sylius.registry.report.data_fetcher')->willReturn(true); $container->getDefinition('sylius.registry.report.data_fetcher')->willReturn($dataFetcherDefinition); diff --git a/spec/DependencyInjection/Compiler/RegisterRenderersPassSpec.php b/spec/DependencyInjection/Compiler/RegisterRenderersPassSpec.php index b95ece8..9a29882 100644 --- a/spec/DependencyInjection/Compiler/RegisterRenderersPassSpec.php +++ b/spec/DependencyInjection/Compiler/RegisterRenderersPassSpec.php @@ -22,12 +22,12 @@ */ final class RegisterRenderersPassSpec extends ObjectBehavior { - function it_should_implement_compiler_pass_interface() + public function it_should_implement_compiler_pass_interface() { $this->shouldImplement(CompilerPassInterface::class); } - function it_processes_with_given_container(ContainerBuilder $container, Definition $rendererDefinition) + public function it_processes_with_given_container(ContainerBuilder $container, Definition $rendererDefinition) { $container->hasDefinition('sylius.registry.report.renderer')->willReturn(true); $container->getDefinition('sylius.registry.report.renderer')->willReturn($rendererDefinition); @@ -40,12 +40,12 @@ function it_processes_with_given_container(ContainerBuilder $container, Definiti $container->findTaggedServiceIds('sylius.report.renderer')->willReturn($rendererServices); $rendererDefinition->addMethodCall('register', ['test', new Reference('sylius.form.type.renderer.test')])->shouldBeCalled(); - $container->setParameter('sylius.report.renderers', ['test' => 'Test renderer'])->shouldBeCalled(); + $container->setParameter('sylius.report.renderers', ['Test renderer' => 'test'])->shouldBeCalled(); $this->process($container); } - function it_does_not_process_if_container_has_not_proper_definition(ContainerBuilder $container) + public function it_does_not_process_if_container_has_not_proper_definition(ContainerBuilder $container) { $container->hasDefinition('sylius.registry.report.renderer')->willReturn(false); $container->getDefinition('sylius.registry.report.renderer')->shouldNotBeCalled(); @@ -53,7 +53,7 @@ function it_does_not_process_if_container_has_not_proper_definition(ContainerBui $this->process($container); } - function it_throws_exception_if_any_renderer_has_improper_attributes(ContainerBuilder $container, Definition $rendererDefinition) + public function it_throws_exception_if_any_renderer_has_improper_attributes(ContainerBuilder $container, Definition $rendererDefinition) { $container->hasDefinition('sylius.registry.report.renderer')->willReturn(true); $container->getDefinition('sylius.registry.report.renderer')->willReturn($rendererDefinition); diff --git a/spec/Form/EventListener/BuildReportDataFetcherFormSubscriberSpec.php b/spec/Form/EventListener/BuildReportDataFetcherFormSubscriberSpec.php index 4a96fc8..a73efca 100644 --- a/spec/Form/EventListener/BuildReportDataFetcherFormSubscriberSpec.php +++ b/spec/Form/EventListener/BuildReportDataFetcherFormSubscriberSpec.php @@ -13,6 +13,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportDataFetcherFormSubscriber; use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Report\DataFetcher\DataFetcherInterface; use Sylius\Component\Report\Model\ReportInterface; @@ -27,17 +28,17 @@ */ final class BuildReportDataFetcherFormSubscriberSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportDataFetcherFormSubscriber'); + $this->shouldHaveType(BuildReportDataFetcherFormSubscriber::class); } - function it_implements_data_fetcher_interface() + public function it_implements_data_fetcher_interface() { $this->shouldImplement(EventSubscriberInterface::class); } - function let(ServiceRegistryInterface $dataFetcherRegistry, FormFactoryInterface $factory, DataFetcherInterface $dataFetcher) + public function let(ServiceRegistryInterface $dataFetcherRegistry, FormFactoryInterface $factory, DataFetcherInterface $dataFetcher) { $dataFetcherRegistry->get('test_data_fetcher')->willReturn($dataFetcher); $dataFetcher->getType()->willReturn('sylius_data_fetcher_test_type'); @@ -45,7 +46,7 @@ function let(ServiceRegistryInterface $dataFetcherRegistry, FormFactoryInterface $this->beConstructedWith($dataFetcherRegistry, $factory); } - function it_adds_configuration_fields_in_pre_set_data( + public function it_adds_configuration_fields_in_pre_set_data( $factory, ReportInterface $report, FormEvent $event, @@ -69,7 +70,7 @@ function it_adds_configuration_fields_in_pre_set_data( $this->preSetData($event); } - function it_adds_configuration_fields_in_pre_bind( + public function it_adds_configuration_fields_in_pre_bind( $factory, FormEvent $event, Form $form, @@ -91,7 +92,7 @@ function it_adds_configuration_fields_in_pre_bind( $this->preBind($event); } - function it_does_not_allow_to_confidure_fields_in_pre_set_data_for_other_class_then_report(FormEvent $event) + public function it_does_not_allow_to_confidure_fields_in_pre_set_data_for_other_class_then_report(FormEvent $event) { $report = ''; $event->getData()->willReturn($report); diff --git a/spec/Form/EventListener/BuildReportRendererFormSubscriberSpec.php b/spec/Form/EventListener/BuildReportRendererFormSubscriberSpec.php index b3e907b..1dac5e0 100644 --- a/spec/Form/EventListener/BuildReportRendererFormSubscriberSpec.php +++ b/spec/Form/EventListener/BuildReportRendererFormSubscriberSpec.php @@ -13,6 +13,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportRendererFormSubscriber; use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Report\Model\ReportInterface; use Sylius\Component\Report\Renderer\RendererInterface; @@ -27,17 +28,17 @@ */ final class BuildReportRendererFormSubscriberSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportRendererFormSubscriber'); + $this->shouldHaveType(BuildReportRendererFormSubscriber::class); } - function it_implements_data_fetcher_interface() + public function it_implements_data_fetcher_interface() { $this->shouldImplement(EventSubscriberInterface::class); } - function let(ServiceRegistryInterface $rendererRegistry, FormFactoryInterface $factory, RendererInterface $renderer) + public function let(ServiceRegistryInterface $rendererRegistry, FormFactoryInterface $factory, RendererInterface $renderer) { $rendererRegistry->get('test_renderer')->willReturn($renderer); $renderer->getType()->willReturn('sylius_renderer_test_type'); @@ -45,7 +46,7 @@ function let(ServiceRegistryInterface $rendererRegistry, FormFactoryInterface $f $this->beConstructedWith($rendererRegistry, $factory); } - function it_adds_configuration_fields_in_pre_set_data( + public function it_adds_configuration_fields_in_pre_set_data( $factory, ReportInterface $report, FormEvent $event, @@ -69,7 +70,7 @@ function it_adds_configuration_fields_in_pre_set_data( $this->preSetData($event); } - function it_adds_configuration_fields_in_pre_bind( + public function it_adds_configuration_fields_in_pre_bind( $factory, FormEvent $event, Form $form, @@ -91,7 +92,7 @@ function it_adds_configuration_fields_in_pre_bind( $this->preBind($event); } - function it_does_not_allow_to_confidure_fields_in_pre_set_data_for_other_class_then_report(FormEvent $event) + public function it_does_not_allow_to_confidure_fields_in_pre_set_data_for_other_class_then_report(FormEvent $event) { $report = ''; $event->getData()->willReturn($report); diff --git a/spec/Form/Type/Renderer/ChartConfigurationTypeSpec.php b/spec/Form/Type/Renderer/ChartConfigurationTypeSpec.php index 3abc8b5..349bffc 100644 --- a/spec/Form/Type/Renderer/ChartConfigurationTypeSpec.php +++ b/spec/Form/Type/Renderer/ChartConfigurationTypeSpec.php @@ -13,7 +13,9 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\ChartConfigurationType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilder; /** @@ -21,25 +23,20 @@ */ final class ChartConfigurationTypeSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\Type\Renderer\ChartConfigurationType'); + $this->shouldHaveType(ChartConfigurationType::class); } - function it_should_be_abstract_type_object() + public function it_should_be_abstract_type_object() { $this->shouldHaveType(AbstractType::class); } - function it_has_name() + public function it_builds_form_with_type_choice_and_template_choice(FormBuilder $builder) { - $this->getName()->shouldReturn('sylius_renderer_chart'); - } - - function it_builds_form_with_type_choice_and_template_choice(FormBuilder $builder) - { - $builder->add('type', 'choice', Argument::any())->willReturn($builder); - $builder->add('template', 'choice', Argument::any())->willReturn($builder); + $builder->add('type', ChoiceType::class, Argument::any())->willReturn($builder); + $builder->add('template', ChoiceType::class, Argument::any())->willReturn($builder); $this->buildForm($builder, []); } diff --git a/spec/Form/Type/Renderer/RendererChoiceTypeSpec.php b/spec/Form/Type/Renderer/RendererChoiceTypeSpec.php index f7f0a9e..fe990ed 100644 --- a/spec/Form/Type/Renderer/RendererChoiceTypeSpec.php +++ b/spec/Form/Type/Renderer/RendererChoiceTypeSpec.php @@ -12,7 +12,9 @@ namespace spec\Sylius\Bundle\ReportBundle\Form\Type\Renderer; use PhpSpec\ObjectBehavior; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\RendererChoiceType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\OptionsResolver\OptionsResolver; /** @@ -20,7 +22,7 @@ */ final class RendererChoiceTypeSpec extends ObjectBehavior { - function let() + public function let() { $choices = [ 'table' => 'Table renderer', @@ -30,17 +32,17 @@ function let() $this->beConstructedWith($choices); } - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\Type\Renderer\RendererChoiceType'); + $this->shouldHaveType(RendererChoiceType::class); } - function it_should_be_abstract_type_object() + public function it_should_be_abstract_type_object() { $this->shouldHaveType(AbstractType::class); } - function it_sets_default_options(OptionsResolver $resolver) + public function it_sets_default_options(OptionsResolver $resolver) { $choices = [ 'table' => 'Table renderer', @@ -52,13 +54,8 @@ function it_sets_default_options(OptionsResolver $resolver) $this->configureOptions($resolver); } - function it_has_parent() + public function it_has_parent() { - $this->getParent()->shouldReturn('choice'); - } - - function it_has_name() - { - $this->getName()->shouldReturn('sylius_renderer_choice'); + $this->getParent()->shouldReturn(ChoiceType::class); } } diff --git a/spec/Form/Type/Renderer/TableConfigurationTypeSpec.php b/spec/Form/Type/Renderer/TableConfigurationTypeSpec.php index 6968c2d..227b5d5 100644 --- a/spec/Form/Type/Renderer/TableConfigurationTypeSpec.php +++ b/spec/Form/Type/Renderer/TableConfigurationTypeSpec.php @@ -13,7 +13,9 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\TableConfigurationType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilder; /** @@ -21,24 +23,19 @@ */ final class TableConfigurationTypeSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\Type\Renderer\TableConfigurationType'); + $this->shouldHaveType(TableConfigurationType::class); } - function it_should_be_abstract_type_object() + public function it_should_be_abstract_type_object() { $this->shouldHaveType(AbstractType::class); } - function it_has_name() + public function it_builds_form_with_template_choice(FormBuilder $builder) { - $this->getName()->shouldReturn('sylius_renderer_table'); - } - - function it_builds_form_with_template_choice(FormBuilder $builder) - { - $builder->add('template', 'choice', Argument::any())->willReturn($builder); + $builder->add('template', ChoiceType::class, Argument::any())->willReturn($builder); $this->buildForm($builder, []); } diff --git a/spec/Form/Type/ReportTypeSpec.php b/spec/Form/Type/ReportTypeSpec.php index 6ccec66..49120b0 100644 --- a/spec/Form/Type/ReportTypeSpec.php +++ b/spec/Form/Type/ReportTypeSpec.php @@ -15,12 +15,17 @@ use Prophecy\Argument; use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportDataFetcherFormSubscriber; use Sylius\Bundle\ReportBundle\Form\EventListener\BuildReportRendererFormSubscriber; +use Sylius\Bundle\ReportBundle\Form\Type\DataFetcher\DataFetcherChoiceType; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\RendererChoiceType; +use Sylius\Bundle\ReportBundle\Form\Type\ReportType; use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Sylius\Component\Registry\ServiceRegistryInterface; use Sylius\Component\Report\DataFetcher\DataFetcherInterface; use Sylius\Component\Report\Model\Report; use Sylius\Component\Report\Renderer\RendererInterface; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormConfigInterface; @@ -33,22 +38,22 @@ */ final class ReportTypeSpec extends ObjectBehavior { - function let(ServiceRegistryInterface $rendererRegistry, ServiceRegistryInterface $dataFetcherRegistry) + public function let(ServiceRegistryInterface $rendererRegistry, ServiceRegistryInterface $dataFetcherRegistry) { $this->beConstructedWith(Report::class, ['sylius'], $rendererRegistry, $dataFetcherRegistry); } - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Form\Type\ReportType'); + $this->shouldHaveType(ReportType::class); } - function it_should_be_abstract_resource_type_object() + public function it_should_be_abstract_resource_type_object() { $this->shouldHaveType(AbstractResourceType::class); } - function it_build_form_with_proper_fields( + public function it_build_form_with_proper_fields( FormBuilderInterface $builder, FormFactoryInterface $factory, $dataFetcherRegistry, @@ -58,10 +63,10 @@ function it_build_form_with_proper_fields( ) { $builder->getFormFactory()->willReturn($factory); - $builder->add('name', 'text', Argument::any())->shouldBeCalled()->willReturn($builder); - $builder->add('description', 'textarea', Argument::any())->shouldBeCalled()->willReturn($builder); - $builder->add('renderer', 'sylius_renderer_choice', Argument::any())->shouldBeCalled()->willReturn($builder); - $builder->add('dataFetcher', 'sylius_data_fetcher_choice', Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('name', TextType::class, Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('description', TextareaType::class, Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('renderer', RendererChoiceType::class, Argument::any())->shouldBeCalled()->willReturn($builder); + $builder->add('dataFetcher', DataFetcherChoiceType::class, Argument::any())->shouldBeCalled()->willReturn($builder); $builder->addEventSubscriber(Argument::type(BuildReportRendererFormSubscriber::class))->shouldBeCalled()->willReturn($builder); $builder->addEventSubscriber(Argument::type(BuildReportDataFetcherFormSubscriber::class))->shouldBeCalled()->willReturn($builder); @@ -95,7 +100,7 @@ function it_build_form_with_proper_fields( $this->buildForm($builder, []); } - function it_builds_view( + public function it_builds_view( FormConfigInterface $config, FormView $view, FormInterface $form, @@ -114,9 +119,4 @@ function it_builds_view( $this->buildView($view, $form, []); } - - function it_has_name() - { - $this->getName()->shouldReturn('sylius_report'); - } } diff --git a/spec/Renderer/ChartRendererSpec.php b/spec/Renderer/ChartRendererSpec.php index 712451a..487c410 100644 --- a/spec/Renderer/ChartRendererSpec.php +++ b/spec/Renderer/ChartRendererSpec.php @@ -12,9 +12,10 @@ namespace spec\Sylius\Bundle\ReportBundle\Renderer; use PhpSpec\ObjectBehavior; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\ChartConfigurationType; +use Sylius\Bundle\ReportBundle\Renderer\ChartRenderer; use Sylius\Component\Report\DataFetcher\Data; use Sylius\Component\Report\Model\ReportInterface; -use Sylius\Component\Report\Renderer\DefaultRenderers; use Sylius\Component\Report\Renderer\RendererInterface; use Symfony\Component\Templating\EngineInterface; @@ -24,22 +25,22 @@ */ final class ChartRendererSpec extends ObjectBehavior { - function let(EngineInterface $templating) + public function let(EngineInterface $templating) { $this->beConstructedWith($templating); } - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Renderer\ChartRenderer'); + $this->shouldHaveType(ChartRenderer::class); } - function it_should_implement_renderer_interface() + public function it_should_implement_renderer_interface() { $this->shouldImplement(RendererInterface::class); } - function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) + public function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) { $reportData->getData()->willReturn(['month1' => '50', 'month2' => '40']); @@ -59,8 +60,8 @@ function it_renders_data_with_given_configuration(ReportInterface $report, Data $this->render($report, $reportData)->shouldReturn('
Chart Report
'); } - function it_is_a_chart_type() + public function it_is_a_chart_type() { - $this->getType()->shouldReturn(DefaultRenderers::CHART); + $this->getType()->shouldReturn(ChartConfigurationType::class); } } diff --git a/spec/Renderer/TableRendererSpec.php b/spec/Renderer/TableRendererSpec.php index 54fa2ef..a963fd5 100644 --- a/spec/Renderer/TableRendererSpec.php +++ b/spec/Renderer/TableRendererSpec.php @@ -12,9 +12,10 @@ namespace spec\Sylius\Bundle\ReportBundle\Renderer; use PhpSpec\ObjectBehavior; +use Sylius\Bundle\ReportBundle\Form\Type\Renderer\TableConfigurationType; +use Sylius\Bundle\ReportBundle\Renderer\TableRenderer; use Sylius\Component\Report\DataFetcher\Data; use Sylius\Component\Report\Model\ReportInterface; -use Sylius\Component\Report\Renderer\DefaultRenderers; use Sylius\Component\Report\Renderer\RendererInterface; use Symfony\Component\Templating\EngineInterface; @@ -24,22 +25,22 @@ */ final class TableRendererSpec extends ObjectBehavior { - function let(EngineInterface $templating) + public function let(EngineInterface $templating) { $this->beConstructedWith($templating); } - function it_is_initializable() + public function it_is_initializable() { - $this->shouldHaveType('Sylius\Bundle\ReportBundle\Renderer\TableRenderer'); + $this->shouldHaveType(TableRenderer::class); } - function it_should_implement_renderer_interface() + public function it_should_implement_renderer_interface() { $this->shouldImplement(RendererInterface::class); } - function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) + public function it_renders_data_with_given_configuration(ReportInterface $report, Data $reportData, $templating) { $reportData->getLabels()->willReturn(['month', 'user_total']); $reportData->getData()->willReturn(['month1' => '50', 'month2' => '40']); @@ -61,8 +62,8 @@ function it_renders_data_with_given_configuration(ReportInterface $report, Data $this->render($report, $reportData)->shouldReturn('
Table Report
'); } - function it_is_a_table_type() + public function it_is_a_table_type() { - $this->getType()->shouldReturn(DefaultRenderers::TABLE); + $this->getType()->shouldReturn(TableConfigurationType::class); } }
{{ sylius_resource_sort('id', '#') }}{{ sylius_resource_sort('label', label) }}{{ label }}