Skip to content

Commit a120b63

Browse files
authored
Segregation interface (Logger and Profiler) (#276)
* Segregation interface (Logger and Profiler) * fix * move all tests to pgsql * move all tests to pgsql * styleci
1 parent 8e23fcb commit a120b63

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/PdoCommandTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Yiisoft\Db\Pgsql\Tests;
66

7+
use Psr\Log\LoggerAwareInterface;
8+
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
9+
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
710
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
811
use Yiisoft\Db\Tests\Common\CommonPdoCommandTest;
912

@@ -51,4 +54,43 @@ public function testInsertAndReadToArrayColumn(): void
5154

5255
$this->assertSame($arrValue, $columnSchema->phpTypecast($selectData['array_col']));
5356
}
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+
}
5496
}

0 commit comments

Comments
 (0)