sqlitePath = sys_get_temp_dir().'/asteria_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::seedCustomer($this->connection, [ 'entity_id' => 10, 'email' => 'jane@example.com', 'firstname' => 'Jane', 'lastname' => 'Doe', 'telephone' => '555111', 'gender' => 1, 'dob' => '1990-05-01 00:00:00', 'password_hash' => md5('abcsecret12').':abc', 'is_active' => 1, 'group_id' => 99, 'source' => 20, ]); MagentoSchema::seedAddress($this->connection, [ 'entity_id' => 21, 'parent_id' => 10, 'firstname' => 'Jane', 'lastname' => 'Doe', 'street' => "123 Main St\nApt 4", 'city' => 'Austin', 'region' => 'TX', 'postcode' => '78701', 'country_id' => 'US', 'telephone' => '555111', 'company' => 'Acme', ]); } protected function tearDown(): void { DB::purge($this->connection); if (is_file($this->sqlitePath)) { @unlink($this->sqlitePath); } parent::tearDown(); } public function test_it_flattens_customer_and_address_eav_attributes(): void { $reader = new Magento1CustomerReader($this->connection); $customers = $reader->fetchCustomers(0, 50); $this->assertCount(1, $customers); $customer = $customers->first(); $this->assertSame(10, $customer['entity_id']); $this->assertSame('jane@example.com', $customer['email']); $this->assertSame('Jane', $customer['firstname']); $this->assertSame('Doe', $customer['lastname']); $this->assertSame('555111', $customer['telephone']); $this->assertSame('1', (string) $customer['gender']); $this->assertSame('1990-05-01 00:00:00', $customer['dob']); $this->assertSame(md5('abcsecret12').':abc', $customer['password_hash']); $this->assertSame('20', (string) $customer['source']); $addresses = $reader->fetchAddresses([10]); $this->assertCount(1, $addresses); $address = $addresses->first(); $this->assertSame(21, $address['entity_id']); $this->assertSame(10, $address['parent_id']); $this->assertSame("123 Main St\nApt 4", $address['street']); $this->assertSame('Austin', $address['city']); $this->assertSame('US', $address['country_id']); $this->assertSame('Acme', $address['company']); } public function test_it_pages_from_the_last_entity_id(): void { MagentoSchema::seedCustomer($this->connection, [ 'entity_id' => 11, 'email' => 'second@example.com', 'firstname' => 'Second', 'lastname' => 'User', ]); $reader = new Magento1CustomerReader($this->connection); $this->assertCount(1, $reader->fetchCustomers(10, 50)); $this->assertSame('second@example.com', $reader->fetchCustomers(10, 50)->first()['email']); } public function test_it_reads_newsletter_subscribers_by_customer_id_and_email(): void { MagentoSchema::seedSubscriber($this->connection, [ 'subscriber_id' => 1, 'customer_id' => 10, 'subscriber_email' => 'Jane@example.com', 'subscriber_status' => 1, ]); MagentoSchema::seedSubscriber($this->connection, [ 'subscriber_id' => 2, 'customer_id' => 0, 'subscriber_email' => 'guest@example.com', 'subscriber_status' => 1, ]); $reader = new Magento1CustomerReader($this->connection); $forCustomer = $reader->fetchSubscribers([10], ['jane@example.com']); $this->assertCount(1, $forCustomer); $this->assertSame(1, $forCustomer->first()['subscriber_id']); $this->assertSame(1, $forCustomer->first()['subscriber_status']); $paged = $reader->fetchSubscribersAfter(0, 50); $this->assertCount(2, $paged); $this->assertSame(2, $reader->fetchSubscribersAfter(1, 50)->first()['subscriber_id']); } public function test_it_returns_no_subscribers_when_the_table_is_missing(): void { Schema::connection($this->connection)->drop('newsletter_subscriber'); $reader = new Magento1CustomerReader($this->connection); $this->assertTrue($reader->fetchSubscribers([10], ['jane@example.com'])->isEmpty()); $this->assertTrue($reader->fetchSubscribersAfter(0, 50)->isEmpty()); } }