fix(CI): make unit tests PHP 8.5 compatibly

... and do not swallow exceptions

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon
2026-01-09 14:10:35 +01:00
parent 4ca5bc0d9c
commit d0825efae1

View File

@ -194,88 +194,82 @@ class EntityVirtualPropertiesTest extends DatabaseTestCase {
* Get database table fields for Entity class * Get database table fields for Entity class
*/ */
private function getDatabaseTableFields(string $className): array { private function getDatabaseTableFields(string $className): array {
try { // Try to get table name from class
// Try to get table name from class $tableName = $this->getTableNameFromClass($className);
$tableName = $this->getTableNameFromClass($className); if (!$tableName) {
if (!$tableName) {
return [];
}
$schema = $this->connection->createSchema();
$fullTableName = $this->connection->getPrefix() . $tableName;
if (!$schema->hasTable($fullTableName)) {
return [];
}
$table = $schema->getTable($fullTableName);
$columns = $table->getColumns();
$fields = [];
foreach ($columns as $column) {
$fields[] = $column->getName();
}
return $fields;
} catch (\Exception $e) {
// If we can't get table fields, return empty array
return []; return [];
} }
$schema = $this->connection->createSchema();
$fullTableName = $this->connection->getPrefix() . $tableName;
if (!$schema->hasTable($fullTableName)) {
return [];
}
$table = $schema->getTable($fullTableName);
$columns = $table->getColumns();
$fields = [];
foreach ($columns as $column) {
$fields[] = $column->getName();
}
return $fields;
} }
/** /**
* Get table name from Entity class * Get table name from Entity class
*/ */
private function getTableNameFromClass(string $className): ?string { private function getTableNameFromClass(string $className): ?string {
try { $reflection = new ReflectionClass($className);
$reflection = new ReflectionClass($className);
// Try to get table name from protected property // Try to get table name from protected property
if ($reflection->hasProperty('table')) { if ($reflection->hasProperty('table')) {
$tableProperty = $reflection->getProperty('table'); $tableProperty = $reflection->getProperty('table');
if (PHP_VERSION_ID < 80200) {
$tableProperty->setAccessible(true); $tableProperty->setAccessible(true);
}
// Create instance to get table name // Create instance to get table name
$instance = $reflection->newInstanceWithoutConstructor(); $instance = $reflection->newInstanceWithoutConstructor();
$tableName = $tableProperty->getValue($instance); $tableName = $tableProperty->getValue($instance);
if ($tableName) {
return $tableName;
}
}
// Try to get table name from mapper class
$mapperClassName = $className . 'Mapper';
if (class_exists($mapperClassName)) {
$mapperReflection = new ReflectionClass($mapperClassName);
if ($mapperReflection->hasProperty('table')) {
$tableProperty = $mapperReflection->getProperty('table');
if (PHP_VERSION_ID < 80200) {
$tableProperty->setAccessible(true);
}
// Create mapper instance to get table name
$mapperInstance = $mapperReflection->newInstanceWithoutConstructor();
$tableName = $tableProperty->getValue($mapperInstance);
if ($tableName) { if ($tableName) {
return $tableName; return $tableName;
} }
} }
}
// Try to get table name from mapper class // Try to infer table name from class name
$mapperClassName = $className . 'Mapper'; $shortClassName = basename(str_replace('\\', '/', $className));
if (class_exists($mapperClassName)) { $tableName = 'tables_' . strtolower($shortClassName) . 's';
$mapperReflection = new ReflectionClass($mapperClassName);
if ($mapperReflection->hasProperty('table')) {
$tableProperty = $mapperReflection->getProperty('table');
$tableProperty->setAccessible(true);
// Create mapper instance to get table name // Check if table exists
$mapperInstance = $mapperReflection->newInstanceWithoutConstructor(); $schema = $this->connection->createSchema();
$tableName = $tableProperty->getValue($mapperInstance); $fullTableName = $this->connection->getPrefix() . $tableName;
if ($tableName) { if ($schema->hasTable($fullTableName)) {
return $tableName; return $tableName;
}
}
}
// Try to infer table name from class name
$shortClassName = basename(str_replace('\\', '/', $className));
$tableName = 'tables_' . strtolower($shortClassName) . 's';
// Check if table exists
$schema = $this->connection->createSchema();
$fullTableName = $this->connection->getPrefix() . $tableName;
if ($schema->hasTable($fullTableName)) {
return $tableName;
}
} catch (\Exception $e) {
// If we can't get table name, return null
} }
return null; return null;