Skip to content

Commit

Permalink
Add test for INSERT … SELECT
Browse files Browse the repository at this point in the history
Test for #89.
  • Loading branch information
trowski committed Oct 30, 2019
1 parent b0b3eed commit 000e0b4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/LinkTest.php
Expand Up @@ -2,6 +2,7 @@

namespace Amp\Mysql\Test;

use Amp\Iterator;
use Amp\Mysql\CommandResult;
use Amp\Mysql\DataTypes;
use Amp\Mysql\ResultSet;
Expand Down Expand Up @@ -332,4 +333,35 @@ public function testTransaction()
}
$this->assertCount(0, $got);
}

/**
* @depends testTransaction
*/
public function testInsertSelect()
{
/** @var Link $db */
$db = yield $this->getLink("host=".DB_HOST.";user=".DB_USER.";pass=".DB_PASS.";db=test");

$a = 1;

/** @var Transaction $transaction */
$transaction = yield $db->beginTransaction();

try {
/** @var Statement $statement */
$statement = yield $transaction->prepare("SELECT a, b FROM main WHERE a >= ?");

$count = \count(yield Iterator\toArray(yield $statement->execute([$a])));

/** @var Statement $statement */
$statement = yield $transaction->prepare("INSERT INTO main (a, b) SELECT a, b FROM main WHERE a >= ?");

/** @var CommandResult $result */
$result = yield $statement->execute([$a]);

$this->assertSame($count, $result->getAffectedRowCount());
} finally {
yield $transaction->rollback();
}
}
}

0 comments on commit 000e0b4

Please sign in to comment.