Magento1SchemaTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Webkul\BagistoApi\Tests\Unit\Migration;
  3. use App\Services\Asteria\Magento1Schema;
  4. use Illuminate\Support\Facades\DB;
  5. use Tests\TestCase;
  6. class Magento1SchemaTest extends TestCase
  7. {
  8. private string $sqlitePath;
  9. private string $connection = 'asteria_test';
  10. protected function setUp(): void
  11. {
  12. parent::setUp();
  13. $this->sqlitePath = sys_get_temp_dir().'/asteria_schema_'.uniqid('', true).'.sqlite';
  14. touch($this->sqlitePath);
  15. config()->set('database.connections.'.$this->connection, [
  16. 'driver' => 'sqlite',
  17. 'database' => $this->sqlitePath,
  18. 'prefix' => '',
  19. 'foreign_key_constraints' => false,
  20. ]);
  21. DB::purge($this->connection);
  22. MagentoSchema::create($this->connection);
  23. }
  24. protected function tearDown(): void
  25. {
  26. DB::purge($this->connection);
  27. if (is_file($this->sqlitePath)) {
  28. @unlink($this->sqlitePath);
  29. }
  30. parent::tearDown();
  31. }
  32. public function test_it_lists_existing_columns_without_using_generation_expression(): void
  33. {
  34. $schema = new Magento1Schema($this->connection);
  35. $columns = $schema->existingColumns('customer_entity', [
  36. 'entity_id',
  37. 'email',
  38. 'missing_column',
  39. 'generation_expression',
  40. ]);
  41. $this->assertSame(['entity_id', 'email'], $columns);
  42. $this->assertSame([], $schema->existingColumns('does_not_exist', ['entity_id']));
  43. }
  44. }