|
7 | 7 | use Override; |
8 | 8 | use PhpDb\Adapter\Driver\Pdo\Result; |
9 | 9 | use PhpDb\Adapter\Driver\Pdo\Statement; |
| 10 | +use PhpDb\Adapter\Exception\RuntimeException; |
10 | 11 | use PhpDb\Adapter\ParameterContainer; |
11 | 12 | use PhpDbTest\Adapter\Driver\Pdo\TestAsset\TestConnection; |
12 | 13 | use PhpDbTest\Adapter\Driver\Pdo\TestAsset\TestPdo; |
13 | 14 | use PHPUnit\Framework\Attributes\CoversMethod; |
| 15 | +use PHPUnit\Framework\Attributes\DataProvider; |
14 | 16 | use PHPUnit\Framework\TestCase; |
15 | 17 |
|
16 | 18 | #[CoversMethod(Statement::class, 'setDriver')] |
|
22 | 24 | #[CoversMethod(Statement::class, 'prepare')] |
23 | 25 | #[CoversMethod(Statement::class, 'isPrepared')] |
24 | 26 | #[CoversMethod(Statement::class, 'execute')] |
| 27 | +#[CoversMethod(Statement::class, 'bindParametersFromContainer')] |
25 | 28 | final class StatementTest extends TestCase |
26 | 29 | { |
27 | 30 | protected Statement $statement; |
@@ -111,4 +114,29 @@ public function testExecute(): void |
111 | 114 | $this->statement->prepare('SELECT 1'); |
112 | 115 | self::assertInstanceOf(Result::class, $this->statement->execute()); |
113 | 116 | } |
| 117 | + |
| 118 | + /** @return array<string, array{string}> */ |
| 119 | + public static function invalidParameterNameProvider(): array |
| 120 | + { |
| 121 | + return [ |
| 122 | + 'dollar sign' => ['tz$'], |
| 123 | + 'with colon' => [':tz$'], |
| 124 | + 'hyphen' => ['my-param'], |
| 125 | + 'space' => ['my param'], |
| 126 | + 'dot' => ['my.param'], |
| 127 | + 'at sign' => ['param@name'], |
| 128 | + ]; |
| 129 | + } |
| 130 | + |
| 131 | + #[DataProvider('invalidParameterNameProvider')] |
| 132 | + public function testExecuteThrowsOnInvalidParameterName(string $name): void |
| 133 | + { |
| 134 | + $this->statement->setDriver(new TestPdo(new TestConnection($pdo = new TestAsset\SqliteMemoryPdo()))); |
| 135 | + $this->statement->initialize($pdo); |
| 136 | + $this->statement->prepare('SELECT 1'); |
| 137 | + |
| 138 | + $this->expectException(RuntimeException::class); |
| 139 | + $this->expectExceptionMessage('contains invalid characters'); |
| 140 | + $this->statement->execute([$name => 'value']); |
| 141 | + } |
114 | 142 | } |
0 commit comments