From d0825efae15e7f4d5ddfb921462357be3a5f6e1a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 9 Jan 2026 14:10:35 +0100 Subject: [PATCH] fix(CI): make unit tests PHP 8.5 compatibly ... and do not swallow exceptions Signed-off-by: Arthur Schiwon --- tests/unit/Db/EntityVirtualPropertiesTest.php | 120 +++++++++--------- 1 file changed, 57 insertions(+), 63 deletions(-) diff --git a/tests/unit/Db/EntityVirtualPropertiesTest.php b/tests/unit/Db/EntityVirtualPropertiesTest.php index cfe4984a..db5305b8 100644 --- a/tests/unit/Db/EntityVirtualPropertiesTest.php +++ b/tests/unit/Db/EntityVirtualPropertiesTest.php @@ -194,88 +194,82 @@ class EntityVirtualPropertiesTest extends DatabaseTestCase { * Get database table fields for Entity class */ private function getDatabaseTableFields(string $className): array { - try { - // Try to get table name from class - $tableName = $this->getTableNameFromClass($className); - 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 + // Try to get table name from class + $tableName = $this->getTableNameFromClass($className); + 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; } /** * Get table name from Entity class */ private function getTableNameFromClass(string $className): ?string { - try { - $reflection = new ReflectionClass($className); + $reflection = new ReflectionClass($className); - // Try to get table name from protected property - if ($reflection->hasProperty('table')) { - $tableProperty = $reflection->getProperty('table'); + // Try to get table name from protected property + if ($reflection->hasProperty('table')) { + $tableProperty = $reflection->getProperty('table'); + if (PHP_VERSION_ID < 80200) { $tableProperty->setAccessible(true); + } - // Create instance to get table name - $instance = $reflection->newInstanceWithoutConstructor(); - $tableName = $tableProperty->getValue($instance); + // Create instance to get table name + $instance = $reflection->newInstanceWithoutConstructor(); + $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) { 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'); - $tableProperty->setAccessible(true); + // Try to infer table name from class name + $shortClassName = basename(str_replace('\\', '/', $className)); + $tableName = 'tables_' . strtolower($shortClassName) . 's'; - // Create mapper instance to get table name - $mapperInstance = $mapperReflection->newInstanceWithoutConstructor(); - $tableName = $tableProperty->getValue($mapperInstance); + // Check if table exists + $schema = $this->connection->createSchema(); + $fullTableName = $this->connection->getPrefix() . $tableName; - if ($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 + if ($schema->hasTable($fullTableName)) { + return $tableName; } return null;