sqlitePath = sys_get_temp_dir().'/asteria_order_reader_'.uniqid('', true).'.sqlite'; touch($this->sqlitePath); config()->set('database.connections.'.$this->connection, [ 'driver' => 'sqlite', 'database' => $this->sqlitePath, 'prefix' => '', 'foreign_key_constraints' => false, ]); DB::purge($this->connection); MagentoSchema::create($this->connection); MagentoSchema::seedOrder($this->connection, [ 'entity_id' => 10, 'increment_id' => '100000010', 'customer_id' => 5, 'customer_email' => 'jane@example.com', 'customer_firstname' => 'Jane', 'customer_lastname' => 'Doe', 'status' => 'complete', 'state' => 'complete', 'grand_total' => 110, 'subtotal' => 100, 'shipping_amount' => 10, 'items' => [ [ 'item_id' => 101, 'sku' => 'WIG-001', 'name' => 'Lace Wig', 'qty_ordered'=> 1, 'price' => 100, 'row_total' => 100, ], ], 'addresses' => [ [ 'entity_id' => 201, 'address_type' => 'billing', 'firstname' => 'Jane', 'lastname' => 'Doe', 'street' => "123 Main St\nApt 4", 'city' => 'Austin', 'country_id' => 'US', ], [ 'entity_id' => 202, 'address_type' => 'shipping', 'firstname' => 'Jane', 'lastname' => 'Doe', 'street' => '9 Oak Rd', 'city' => 'Dallas', 'country_id' => 'US', ], ], 'payment' => [ 'entity_id' => 301, 'method' => 'paypal_express', 'last_trans_id' => 'ABC123', ], ]); } protected function tearDown(): void { DB::purge($this->connection); if (is_file($this->sqlitePath)) { @unlink($this->sqlitePath); } parent::tearDown(); } public function test_it_reads_orders_items_addresses_and_payments(): void { $reader = new Magento1OrderReader($this->connection); $orders = $reader->fetchOrders(0, 50); $this->assertCount(1, $orders); $order = $orders->first(); $this->assertSame(10, $order['entity_id']); $this->assertSame('100000010', $order['increment_id']); $this->assertSame('jane@example.com', $order['customer_email']); $this->assertSame('complete', $order['status']); $this->assertEquals(110, $order['grand_total']); $items = $reader->fetchItems([10]); $this->assertCount(1, $items); $this->assertSame(101, $items->first()['item_id']); $this->assertSame('WIG-001', $items->first()['sku']); $this->assertNull($items->first()['parent_item_id']); $addresses = $reader->fetchAddresses([10]); $this->assertCount(2, $addresses); $this->assertSame("123 Main St\nApt 4", $addresses->first()['street']); $payments = $reader->fetchPayments([10]); $this->assertCount(1, $payments); $this->assertSame('paypal_express', $payments->first()['method']); $this->assertSame('ABC123', $payments->first()['last_trans_id']); } public function test_it_pages_from_the_last_entity_id(): void { MagentoSchema::seedOrder($this->connection, [ 'entity_id' => 11, 'increment_id' => '100000011', 'customer_email'=> 'second@example.com', ]); $reader = new Magento1OrderReader($this->connection); $page = $reader->fetchOrders(10, 50); $this->assertCount(1, $page); $this->assertSame('100000011', $page->first()['increment_id']); } }