Skip to content

Commit e91e5ad

Browse files
committed
Fix createTable
1 parent 360b3dd commit e91e5ad

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Domain/Subscription/Service/Manager/DynamicListAttrTablesManager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\Core\Domain\Subscription\Service\Manager;
66

77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\Exception\TableExistsException;
89
use Doctrine\DBAL\Schema\Table;
910
use InvalidArgumentException;
1011
use PhpList\Core\Domain\Subscription\Model\AttributeTypeEnum;
@@ -77,6 +78,12 @@ public function createOptionsTableIfNotExists(string $listTable): void
7778
$table->setPrimaryKey(['id']);
7879
$table->addUniqueIndex(['name'], 'uniq_' . $fullTableName . '_name');
7980

80-
$schemaManager->createTable($table);
81+
try {
82+
$schemaManager->createTable($table);
83+
} catch (TableExistsException $e) {
84+
// Table was created by a concurrent process or a previous test run.
85+
// Since this method is idempotent by contract, swallow the exception.
86+
return;
87+
}
8188
}
8289
}

tests/Integration/Domain/Subscription/Service/DynamicListAttrManagerFunctionalTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpList\Core\TestingSupport\Traits\DatabaseTestTrait;
1212
use PHPUnit\Framework\Assert;
1313
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
14+
use Throwable;
1415

1516
/**
1617
* Functional test for DynamicListAttrManager and DynamicListAttrRepository working together
@@ -90,4 +91,24 @@ public function testCreateInsertAndFetchOptionsEndToEnd(): void
9091
Assert::assertNotNull($oneName);
9192
Assert::assertTrue(in_array($oneName, ['Blue', 'Red'], true));
9293
}
94+
95+
protected function tearDown(): void
96+
{
97+
try {
98+
if ($this->entityManager !== null) {
99+
$connection = $this->entityManager->getConnection();
100+
$fullTable = 'phplist_listattr_colours';
101+
// Use raw SQL for cleanup to avoid relying on SchemaManager in tests
102+
$connection->executeStatement('DROP TABLE IF EXISTS ' . $fullTable);
103+
}
104+
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
105+
} catch (Throwable $e) {
106+
// Ignore cleanup failures to not mask test results
107+
} finally {
108+
$this->repo = null;
109+
$this->manager = null;
110+
$this->tablesManager = null;
111+
parent::tearDown();
112+
}
113+
}
93114
}

0 commit comments

Comments
 (0)