Skip to content

Commit

Permalink
minor changes on classes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
songecko committed Sep 1, 2018
1 parent 59fcea5 commit 1537c61
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 77 deletions.
4 changes: 1 addition & 3 deletions features/admin/seeing_report_details.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ Feature: Seeing reports details
@ui
Scenario: Seeing reports basic information
When I view details of the report "2018_sales"
Then his code should be "2018_sales"
And his name should be "Sales 2018"
And his description should be "Sales statistics for year 2018"
Then I should see the "Show report "Sales 2018"" header title
2 changes: 1 addition & 1 deletion spec/Model/ReportSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function it_has_a_default_renderer_configuration(): void

function it_has_a_default_data_fetcher_configuration(): void
{
$this->getDataFetcherConfiguration()->shouldHaveCount(1);
$this->getDataFetcherConfiguration()->shouldHaveCount(3);
}

function it_is_timestampable(): void
Expand Down
5 changes: 5 additions & 0 deletions src/DataFetcher/DefaultDataFetchers.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ final class DefaultDataFetchers
* Number of orders data fetcher
*/
const NUMBER_OF_ORDERS = 'odiseo_sylius_report_data_fetcher_number_of_orders';

/**
* Payment state orders data fetcher
*/
const PAYMENT_STATE_ORDERS = 'odiseo_sylius_report_data_fetcher_payment_state_orders';
}
82 changes: 82 additions & 0 deletions src/DataFetcher/PaymentStateOrdersDataFetcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Odiseo\SyliusReportPlugin\DataFetcher;

use Doctrine\DBAL\Statement;
use Doctrine\ORM\EntityManager;
use Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\PaymentStateOrdersType;
use Sylius\Component\Order\Model\OrderInterface;

/**
* @author Diego D'amico <diego@odiseo.com.ar>
*/
class PaymentStateOrdersDataFetcher implements DataFetcherInterface
{
/**
* @var EntityManager
*/
protected $entityManager;

/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}

/**
* {@inheritdoc}
*/
protected function getData()
{
$queryBuilder = $this->entityManager->getConnection()->createQueryBuilder();

$queryBuilder
->select('o.payment_state as "Payment State"', 'COUNT(o.id) as "Number of orders"')
->from($this->entityManager->getClassMetadata(OrderInterface::class)->getTableName(), 'o')
->groupBy('payment_state')
;

/** @var Statement $stmt */
$stmt = $queryBuilder->execute();

return $stmt->fetchAll();
}

/**
* @param array $configuration
*
* @return Data $data
*/
public function fetch(array $configuration)
{
$data = new Data();

$rawData = $this->getData();

if (empty($rawData)) {
return $data;
}

$labels = array_keys($rawData[0]);
$data->setLabels($labels);

$fetched = [];
foreach ($rawData as $row) {
$fetched[$row[$labels[0]]] = $row[$labels[1]];
}

$data->setData($fetched);

return $data;
}

/**
* {@inheritdoc}
*/
public function getType()
{
return PaymentStateOrdersType::class;
}
}
19 changes: 19 additions & 0 deletions src/Form/Type/DataFetcher/PaymentStateOrdersType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Odiseo\SyliusReportPlugin\Form\Type\DataFetcher;

use Symfony\Component\Form\AbstractType;

/**
* @author Diego D'amico <diego@odiseo.com.ar>
*/
class PaymentStateOrdersType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'odiseo_sylius_report_data_fetcher_payment_state_orders';
}
}
11 changes: 8 additions & 3 deletions src/Model/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Odiseo\SyliusReportPlugin\Model;

use Odiseo\SyliusReportPlugin\DataFetcher\DefaultDataFetchers;
use Odiseo\SyliusReportPlugin\DataFetcher\TimePeriod;
use Odiseo\SyliusReportPlugin\Renderer\DefaultRenderers;
use Sylius\Component\Resource\Model\TimestampableTrait;

Expand Down Expand Up @@ -62,7 +63,11 @@ class Report implements ReportInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->dataFetcherConfiguration = ['end' => new \DateTime()];
$this->dataFetcherConfiguration = [
'start' => new \DateTime('10 years'),
'end' => new \DateTime(),
'period' => TimePeriod::PERIOD_MONTH
];
}

/**
Expand Down Expand Up @@ -132,7 +137,7 @@ public function getDataFetcher()
/**
* {@inheritdoc}
*/
public function setDataFetcher($dataFetcher)
public function setDataFetcher(string $dataFetcher)
{
$this->dataFetcher = $dataFetcher;
}
Expand All @@ -148,7 +153,7 @@ public function getRenderer()
/**
* {@inheritdoc}
*/
public function setRenderer($renderer)
public function setRenderer(string $renderer)
{
$this->renderer = $renderer;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/ReportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getRenderer();
/**
* @param string $renderer
*/
public function setRenderer($renderer);
public function setRenderer(string $renderer);

/**
* @return array
Expand All @@ -61,7 +61,7 @@ public function getDataFetcher();
/**
* @param string $dataFetcher
*/
public function setDataFetcher($dataFetcher);
public function setDataFetcher(string $dataFetcher);

/**
* @return array
Expand Down
13 changes: 6 additions & 7 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ services:
tags:
- { name: odiseo_sylius_report.data_fetcher, fetcher: odiseo_sylius_report_data_fetcher_number_of_orders, label: "odiseo_sylius_report.data_fetcher.number_of_orders" }

odiseo_sylius_report.data_fetcher.payment_state_orders:
class: Odiseo\SyliusReportPlugin\DataFetcher\PaymentStateOrdersDataFetcher
arguments: ['@doctrine.orm.entity_manager']
tags:
- { name: odiseo_sylius_report.data_fetcher, fetcher: odiseo_sylius_report_data_fetcher_payment_state_orders, label: "odiseo_sylius_report.data_fetcher.payment_state_orders" }

#REPORT RENDERER CONFIGURATION TYPES
odiseo_sylius_report.form.type.renderer.configuration.chart:
class: Odiseo\SyliusReportPlugin\Form\Type\Renderer\ChartConfigurationType
Expand All @@ -81,13 +87,6 @@ services:
tags:
- { name: form.type, alias: odiseo_sylius_report_renderer_table }

#REPORT DATA FETCHER CONFIGURATION TYPES
#odiseo_sylius_report.form.type.data_fetcher.configuration.user_registration:
# class: Odiseo\SyliusReportPlugin\Form\Type\DataFetcher\UserRegistrationConfigurationType
# arguments: ['@doctrine.orm.entity_manager']
# tags:
# - { name: form.type, alias: odiseo_sylius_report_renderer_chart }

#LISTENERS
odiseo_sylius_report.listener.admin.menu_builder:
class: Odiseo\SyliusReportPlugin\Menu\AdminMenuListener
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ odiseo_sylius_report:
user_registration: User registration
sales_total: Sales Total
number_of_orders: Number of orders
payment_state_orders: Payment state orders

odiseo_sylius_report_renderer_table: Table renderer
odiseo_sylius_report_renderer_chart: Chart renderer
odiseo_sylius_report_data_fetcher_user_registration: User Registration
odiseo_sylius_report_data_fetcher_sales_total: Sales Total
odiseo_sylius_report_number_of_orders: Number of orders
odiseo_sylius_report_data_fetcher_number_of_orders: Number of orders
odiseo_sylius_report_data_fetcher_payment_state_orders: Payment state orders
8 changes: 3 additions & 5 deletions src/Resources/views/noDataTemplate.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<div class="ui warning message">
<div class="header">
{{ 'sylius.ui.no_data'|trans }}
</div>
</div>
{% import '@SyliusUi/Macro/messages.html.twig' as messages %}

{{ messages.info('odiseo_sylius_report.ui.there_are_no_reports_results') }}
3 changes: 3 additions & 0 deletions tests/Behat/Context/Setup/ReportContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Behat\Behat\Context\Context;
use Doctrine\ORM\EntityManagerInterface;
use Odiseo\SyliusReportPlugin\DataFetcher\DefaultDataFetchers;
use Odiseo\SyliusReportPlugin\Doctrine\ORM\ReportRepositoryInterface;
use Odiseo\SyliusReportPlugin\Model\ReportInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
Expand Down Expand Up @@ -67,6 +68,8 @@ private function createReport(string $code, string $name, string $description):
$report->setCode($code);
$report->setName($name);
$report->setDescription($description);
$report->setDataFetcher(DefaultDataFetchers::PAYMENT_STATE_ORDERS);
$report->setDataFetcherConfiguration([]);

return $report;
}
Expand Down
24 changes: 3 additions & 21 deletions tests/Behat/Context/Ui/Admin/ManagingReportsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,12 @@ public function iViewDetailsOfTheReport(ReportInterface $report)
}

/**
* @Then his code should be :code
* @Then I should see the "Show report :reportName" header title
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function hisCodeShouldBe($code)
public function iShouldSeeTheShowReportHeaderTitle($reportName)
{
Assert::same($this->showPage->getReportCode(), $code);
}

/**
* @Then his name should be :name
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function hisNameShouldBe($name)
{
Assert::same($this->showPage->getReportName(), $name);
}

/**
* @Then his description should be :description
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function hisDescriptionShouldBe($description)
{
Assert::same($this->showPage->getReportDescription(), $description);
Assert::contains($this->showPage->getHeaderTitle(), $reportName);
}

/**
Expand Down
24 changes: 3 additions & 21 deletions tests/Behat/Page/Admin/Report/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,9 @@ class ShowPage extends SymfonyPage implements ShowPageInterface
/**
* {@inheritdoc}
*/
public function getReportCode()
public function getHeaderTitle()
{
return $this->getElement('code')->getText();
}

/**
* {@inheritdoc}
*/
public function getReportName()
{
return $this->getElement('name')->getText();
}

/**
* {@inheritdoc}
*/
public function getReportDescription()
{
return $this->getElement('description')->getText();
return $this->getElement('header_title')->getText();
}

/**
Expand All @@ -55,9 +39,7 @@ public function getRouteName()
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#odiseo_sylius_report_code',
'name' => '#odiseo_sylius_report_name',
'description' => '#odiseo_sylius_report_description'
'header_title' => '#wrapper .header .content',
]);
}
}
14 changes: 1 addition & 13 deletions tests/Behat/Page/Admin/Report/ShowPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,5 @@ interface ShowPageInterface extends PageInterface
* @return string
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function getReportCode();

/**
* @return string
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function getReportName();

/**
* @return string
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
public function getReportDescription();
public function getHeaderTitle();
}
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit 1537c61

Please sign in to comment.