Skip to content

Commit

Permalink
Add test for Mysqli\Result
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Feb 10, 2023
1 parent e002157 commit 9555f22
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/Functional/Driver/Mysqli/ResultTest.php
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Driver\Mysqli;

use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;

/** @requires extension mysqli */
final class ResultTest extends FunctionalTestCase
{
protected function setUp(): void
{
if (TestUtil::isDriverOneOf('mysqli')) {
$this->connection->executeQuery('CREATE TABLE my_table (my_col_1 INT NOT NULL);');

return;
}

self::markTestSkipped('This test requires the mysqli driver.');
}

protected function tearDown(): void
{
$this->connection->executeStatement('DROP TABLE IF EXISTS my_table;');
}

public function testSuccessfulRowCountFromAffectedRows(): void
{
self::assertSame(0, $this->connection->getNativeConnection()->affected_rows);

$result = $this->connection->executeQuery('INSERT INTO my_table VALUES(7);');

self::assertSame(1, $this->connection->getNativeConnection()->affected_rows);
self::assertSame(1, $result->rowCount());
}

public function testFailingRowCountFromAffectedRows(): void
{
self::assertSame(0, $this->connection->getNativeConnection()->affected_rows);

// @todo: Find a query or a command sequence capable to reproduce the -1 result.
$result = $this->connection->executeQuery('INSERT INTO my_table VALUES(7);');

self::assertSame(-1, $this->connection->getNativeConnection()->affected_rows);
self::assertSame(-1, $result->rowCount());
}
}

0 comments on commit 9555f22

Please sign in to comment.