Skip to content

Commit

Permalink
Fix test enable query log (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Nov 26, 2020
1 parent 9607e5f commit 058f8bb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

env:
COMPOSER_ROOT_VERSION: "dev-master"
extensions: dom, json, pdo, pdo_mysql, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.9.0preview1
extensions: dom, json, pdo, pdo_mysql, pdo_oci, pdo_pgsql, pdo_sqlite, pdo_sqlsrv-5.9.0preview1, oci8
key: cache-v1

runs-on: ${{ matrix.os }}
Expand All @@ -33,6 +33,11 @@ jobs:
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
oci:
image: wnameless/oracle-xe-11g-r2:latest
ports:
- 1521:1521
options: --name=oci
postgres:
image: postgres:13
env:
Expand Down
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ filter:
- "src/*"

tools:
php_code_coverage:
enabled: true
external_code_coverage:
timeout: 660

build:
nodes:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"Yiisoft\\ActiveRecord\\Tests\\": "vendor/yiisoft/active-record/tests",
"Yiisoft\\Db\\Mssql\\Tests\\": "vendor/yiisoft/db-mssql/tests",
"Yiisoft\\Db\\Mysql\\Tests\\": "vendor/yiisoft/db-mysql/tests",
"Yiisoft\\Db\\Oracle\\Tests\\": "vendor/yiisoft/db-oracle/tests",
"Yiisoft\\Db\\Pgsql\\Tests\\": "vendor/yiisoft/db-pgsql/tests",
"Yiisoft\\Db\\Sqlite\\Tests\\": "vendor/yiisoft/db-sqlite/tests"
}
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<testsuite name="Mysql">
<directory>./vendor/yiisoft/db-mysql/tests</directory>
</testsuite>
<testsuite name="Oracle">
<directory>./vendor/yiisoft/db-oracle/tests</directory>
</testsuite>
<testsuite name="Pgsql">
<directory>./vendor/yiisoft/db-pgsql/tests</directory>
</testsuite>
Expand Down
24 changes: 16 additions & 8 deletions src/TestUtility/TestConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public function testEnableQueryLog(): void

$db->createCommand()->createTable('qlog1', ['id' => 'pk'])->execute();

$this->assertCount(1, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(1, $message->all());
$this->assertCount(1, $this->getInaccessibleProperty($this->profiler, 'messages'));
$this->assertNotNull($db->getTableSchema('qlog1', true));

Expand All @@ -203,7 +204,8 @@ public function testEnableQueryLog(): void

$db->createCommand('SELECT * FROM {{qlog1}}')->queryAll();

$this->assertCount(1, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(1, $message->all());
$this->assertCount(1, $this->getInaccessibleProperty($this->profiler, 'messages'));

/* profiling only */
Expand All @@ -215,7 +217,8 @@ public function testEnableQueryLog(): void

$db->createCommand()->createTable('qlog2', ['id' => 'pk'])->execute();

$this->assertCount(0, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(0, $message->all());
$this->assertCount(1, $this->getInaccessibleProperty($this->profiler, 'messages'));
$this->assertNotNull($db->getTableSchema('qlog2', true));

Expand All @@ -224,7 +227,8 @@ public function testEnableQueryLog(): void

$db->createCommand('SELECT * FROM {{qlog2}}')->queryAll();

$this->assertCount(0, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(0, $message->all());
$this->assertCount(1, $this->getInaccessibleProperty($this->profiler, 'messages'));

/* logging only */
Expand All @@ -236,7 +240,8 @@ public function testEnableQueryLog(): void

$db->createCommand()->createTable('qlog3', ['id' => 'pk'])->execute();

$this->assertCount(1, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(1, $message->all());
$this->assertCount(0, $this->getInaccessibleProperty($this->profiler, 'messages'));
$this->assertNotNull($db->getTableSchema('qlog3', true));

Expand All @@ -245,7 +250,8 @@ public function testEnableQueryLog(): void

$db->createCommand('SELECT * FROM {{qlog3}}')->queryAll();

$this->assertCount(1, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(1, $message->all());
$this->assertCount(0, $this->getInaccessibleProperty($this->profiler, 'messages'));

/* disabled */
Expand All @@ -257,13 +263,15 @@ public function testEnableQueryLog(): void

$db->createCommand()->createTable('qlog4', ['id' => 'pk'])->execute();

$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertNotNull($db->getTableSchema('qlog4', true));
$this->assertCount(0, $this->getInaccessibleProperty($this->logger, 'messages'));
$this->assertCount(0, $message->all());
$this->assertCount(0, $this->getInaccessibleProperty($this->profiler, 'messages'));

$db->createCommand('SELECT * FROM {{qlog4}}')->queryAll();

$this->assertCount(0, $this->getInaccessibleProperty($this->logger, 'messages'));
$message = $this->getInaccessibleProperty($this->logger, 'messages');
$this->assertCount(0, $message->all());
$this->assertCount(0, $this->getInaccessibleProperty($this->profiler, 'messages'));
}

Expand Down

0 comments on commit 058f8bb

Please sign in to comment.