Skip to content

PHPUnit\Framework\Exception does not handle string error codes (PDOException with error code 'HY000', for example) #5965

@ludeus

Description

@ludeus
Q A
PHPUnit version 10.5.33
PHP version 8.3
Installation Method Composer

Summary

I encountered an issue where a PDOException with the error code 'HY000' is caught and rethrown in phpunit/src/Framework/Constraint/Cardinality/Count.php:70, but PHPUnit throws an error because PHPUnit\Framework\Exception only accepts integer error codes.

How to reproduce

  1. Use a test case that triggers a PDOException with the error code 'HY000'.
  2. The exception is caught and rethrown in Count.php:70 as follows:
    try {
        $other = $other->getIterator();
    } catch (\Exception $e) {
        throw new Exception(
            $e->getMessage(),
            $e->getCode(), // This throws the error as it passes 'HY000' (a string) instead of an integer
            $e
        );
    }
  3. Since PHPUnit\Framework\Exception expects an integer for the error code, it causes a type mismatch, resulting in an error.

Metadata

Metadata

Labels

type/bugSomething is broken

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions