Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RefundedTest.php
Go to the documentation of this file.
1 <?php
7 
11 class RefundedTest extends \PHPUnit\Framework\TestCase
12 {
16  private $collection;
17 
21  private $objectManager;
22 
23  protected function setUp()
24  {
26  $this->collection = $this->objectManager->create(
27  \Magento\Sales\Model\ResourceModel\Report\Refunded\Collection\Refunded::class
28  );
29  $this->collection->setPeriod('day')
30  ->setDateRange(null, null)
31  ->addStoreFilter([1]);
32  }
33 
40  public function testGetItems()
41  {
43  $order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
44  $order->loadByIncrementId('100000001');
45  $creditmemoCreatedAt = $order->getCreditmemosCollection()->getFirstItem()->getCreatedAt();
47  $dateTime = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\DateTimeFactory::class)
48  ->create();
50  $timezone = $this->objectManager->create(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
51  $creditmemoCreatedAt = $timezone->formatDateTime(
52  $creditmemoCreatedAt,
53  \IntlDateFormatter::SHORT,
54  \IntlDateFormatter::NONE,
55  null,
56  null,
57  'yyyy-MM-dd'
58  );
59  $creditmemoCreatedAtDate = $dateTime->date('Y-m-d', $creditmemoCreatedAt);
60 
61  $expectedResult = [
62  [
63  'orders_count' => 1,
64  'refunded' => 50,
65  'online_refunded' => 50,
66  'offline_refunded' => 0,
67  'period' => $creditmemoCreatedAtDate
68  ],
69  ];
70  $actualResult = [];
72  foreach ($this->collection->getItems() as $reportItem) {
73  $actualResult[] = array_intersect_key($reportItem->getData(), $expectedResult[0]);
74  }
75  $this->assertEquals($expectedResult, $actualResult);
76  }
77 }
$order
Definition: order.php:55