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