|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Doctrine\DBAL\Tests\Functional\Driver\Mysqli; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Driver\Mysqli\Statement; |
| 8 | +use Doctrine\DBAL\Statement as WrapperStatement; |
| 9 | +use Doctrine\DBAL\Tests\FunctionalTestCase; |
| 10 | +use Doctrine\DBAL\Tests\TestUtil; |
| 11 | +use Error; |
| 12 | +use ErrorException; |
| 13 | +use ReflectionProperty; |
| 14 | + |
| 15 | +use function restore_error_handler; |
| 16 | +use function set_error_handler; |
| 17 | + |
| 18 | +use const PHP_VERSION_ID; |
| 19 | + |
| 20 | +/** @requires extension mysqli */ |
| 21 | +class StatementTest extends FunctionalTestCase |
| 22 | +{ |
| 23 | + protected function setUp(): void |
| 24 | + { |
| 25 | + parent::setUp(); |
| 26 | + |
| 27 | + if (TestUtil::isDriverOneOf('mysqli')) { |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + self::markTestSkipped('This test requires the mysqli driver.'); |
| 32 | + } |
| 33 | + |
| 34 | + public function testStatementsAreDeallocatedProperly(): void |
| 35 | + { |
| 36 | + $statement = $this->connection->prepare('SELECT 1'); |
| 37 | + |
| 38 | + $property = new ReflectionProperty(WrapperStatement::class, 'stmt'); |
| 39 | + $property->setAccessible(true); |
| 40 | + |
| 41 | + $driverStatement = $property->getValue($statement); |
| 42 | + |
| 43 | + $mysqliProperty = new ReflectionProperty(Statement::class, 'stmt'); |
| 44 | + $mysqliProperty->setAccessible(true); |
| 45 | + |
| 46 | + $mysqliStatement = $mysqliProperty->getValue($driverStatement); |
| 47 | + |
| 48 | + unset($statement, $driverStatement); |
| 49 | + |
| 50 | + if (PHP_VERSION_ID < 80000) { |
| 51 | + $this->expectException(ErrorException::class); |
| 52 | + $this->expectExceptionMessage('mysqli_stmt::execute(): Couldn\'t fetch mysqli_stmt'); |
| 53 | + } else { |
| 54 | + $this->expectException(Error::class); |
| 55 | + $this->expectExceptionMessage('mysqli_stmt object is already closed'); |
| 56 | + } |
| 57 | + |
| 58 | + set_error_handler(static function (int $errorNumber, string $error, string $file, int $line): void { |
| 59 | + throw new ErrorException($error, 0, $errorNumber, $file, $line); |
| 60 | + }); |
| 61 | + |
| 62 | + try { |
| 63 | + $mysqliStatement->execute(); |
| 64 | + } finally { |
| 65 | + restore_error_handler(); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments