| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace Webkul\BagistoApi\Tests\Unit\Migration;
- use App\Services\Asteria\Magento1CustomerReader;
- use Illuminate\Support\Facades\DB;
- use Tests\TestCase;
- class Magento1CustomerReaderTest extends TestCase
- {
- private string $sqlitePath;
- private string $connection = 'asteria_test';
- protected function setUp(): void
- {
- parent::setUp();
- $this->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,
- ]);
- 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']);
- $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']);
- }
- }
|