|
4 | 4 |
|
5 | 5 | namespace Yiisoft\Db\Pgsql\Tests; |
6 | 6 |
|
| 7 | +use Psr\Log\LoggerAwareInterface; |
| 8 | +use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand; |
| 9 | +use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
7 | 10 | use Yiisoft\Db\Pgsql\Tests\Support\TestTrait; |
8 | 11 | use Yiisoft\Db\Tests\Common\CommonPdoCommandTest; |
9 | 12 |
|
@@ -51,4 +54,43 @@ public function testInsertAndReadToArrayColumn(): void |
51 | 54 |
|
52 | 55 | $this->assertSame($arrValue, $columnSchema->phpTypecast($selectData['array_col'])); |
53 | 56 | } |
| 57 | + |
| 58 | + public function testCommandLogging(): void |
| 59 | + { |
| 60 | + $db = $this->getConnection(true); |
| 61 | + |
| 62 | + $sql = 'SELECT * FROM "customer" LIMIT 1'; |
| 63 | + |
| 64 | + /** @var AbstractPdoCommand $command */ |
| 65 | + $command = $db->createCommand(); |
| 66 | + $this->assertInstanceOf(PdoCommandInterface::class, $command); |
| 67 | + $this->assertInstanceOf(LoggerAwareInterface::class, $command); |
| 68 | + $command->setSql($sql); |
| 69 | + |
| 70 | + $this->assertSame($sql, $command->getSql()); |
| 71 | + |
| 72 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::queryOne'])); |
| 73 | + $command->queryOne(); |
| 74 | + |
| 75 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::queryAll'])); |
| 76 | + $command->queryAll(); |
| 77 | + |
| 78 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::queryColumn'])); |
| 79 | + $command->queryColumn(); |
| 80 | + |
| 81 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::queryScalar'])); |
| 82 | + $command->queryScalar(); |
| 83 | + |
| 84 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::query'])); |
| 85 | + $command->query(); |
| 86 | + |
| 87 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::execute'])); |
| 88 | + $command->execute(); |
| 89 | + |
| 90 | + $sql = 'INSERT INTO "customer" ("name", "email") VALUES (\'test\', \'email@email\') RETURNING "id"'; |
| 91 | + $command->setLogger($this->createQueryLogger($sql, ['Yiisoft\Db\Driver\Pdo\AbstractPdoCommand::insertWithReturningPks'])); |
| 92 | + $command->insertWithReturningPks('{{%customer}}', ['name' => 'test', 'email' => 'email@email']); |
| 93 | + |
| 94 | + $db->close(); |
| 95 | + } |
54 | 96 | } |
0 commit comments