Skip to content

Commit

Permalink
Merge pull request EC-CUBE#1578 from nanasess/fix-monthly-order-test
Browse files Browse the repository at this point in the history
毎月1日にテストが失敗するのを修正
  • Loading branch information
chihiro-adachi committed Jun 1, 2016
2 parents e2ac20e + 77bc5fb commit 7e8d72e
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tests/Eccube/Tests/Web/Admin/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testIndexWithSales()
$Customer = $this->createCustomer();
$Today = new \DateTime();
$Yesterday = new \DateTime('-1 days');

$OrderNew = $this->app['eccube.repository.order_status']->find($this->app['config']['order_new']);
$OrderPending = $this->app['eccube.repository.order_status']->find($this->app['config']['order_pending']);
$OrderCancel = $this->app['eccube.repository.order_status']->find($this->app['config']['order_cancel']);
Expand Down Expand Up @@ -104,12 +105,45 @@ public function testIndexWithSales()
$this->actual = str_replace(',', '', $match[2]);
$this->verify('昨日の売上件数');

// 当月の受注を取得する
$firstDate = clone $Today;
$firstDate->setDate($Today->format('Y'), $Today->format('m'), 1);
$firstDate->setTime(0, 0 ,0);
$endDate = clone $firstDate;
$endDate->setDate($Today->format('Y'), $Today->format('m'), $Today->format('t'));
$endDate->setTime(23, 59, 59);

$qb = $this->app['eccube.repository.order']->createQueryBuilder('o');
$qb->andWhere($qb->expr()->notIn('o.OrderStatus',
array(
$OrderPending->getId(),
$OrderProcessing->getId(),
$OrderCancel->getId()
)))
->andWhere('o.order_date BETWEEN :firstDate AND :endDate')
->setParameters(
array(
'firstDate' => $firstDate,
'endDate' => $endDate
)
);
$MonthlyOrders = $qb->getQuery()->getResult();

preg_match('/^¥ ([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('.monthly_sale')->text()), $match);
$this->expected = $todaysSales + $yesterdaysSales;
$this->expected = array_reduce( // MonthlyOrders の payment_total をすべて足す
array_map(
function ($Order) {
return $Order->getPaymentTotal();
}, $MonthlyOrders
),
function ($carry, $item) {
return $carry += $item;
}
);
$this->actual = str_replace(',', '', $match[1]);
$this->verify('今月の売上');

$this->expected = 6;
$this->expected = count($MonthlyOrders);
$this->actual = str_replace(',', '', $match[2]);
$this->verify('今月の売上件数');
}
Expand Down

0 comments on commit 7e8d72e

Please sign in to comment.