Skip to content

Commit

Permalink
conversion to PHP data types is done in drivers to fix Doctrine incom…
Browse files Browse the repository at this point in the history
…patiblity [closes #14]
  • Loading branch information
JanTvrdik committed Apr 7, 2015
1 parent e4658dc commit c89264c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function rollbackTransaction()
public function lock()
{
$lock = $this->dbal->escapeString(self::LOCK_NAME);
$result = $this->dbal->query("SELECT GET_LOCK($lock, 3) AS `result`")[0]['result'];
$result = (int) $this->dbal->query("SELECT GET_LOCK($lock, 3) AS `result`")[0]['result'];
if ($result !== 1) {
throw new LockException('Unable to acquire a lock.');
}
Expand All @@ -76,7 +76,7 @@ public function lock()
public function unlock()
{
$lock = $this->dbal->escapeString(self::LOCK_NAME);
$result = $this->dbal->query("SELECT RELEASE_LOCK($lock) AS `result`")[0]['result'];
$result = (int) $this->dbal->query("SELECT RELEASE_LOCK($lock) AS `result`")[0]['result'];
if ($result !== 1) {
throw new LockException('Unable to release a lock.');
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public function insertMigration(Migration $migration)
")
");

$migration->id = $this->dbal->query('SELECT LAST_INSERT_ID() AS `id`')[0]['id'];
$migration->id = (int) $this->dbal->query('SELECT LAST_INSERT_ID() AS `id`')[0]['id'];
}


Expand All @@ -128,11 +128,11 @@ public function getAllMigrations()
$result = $this->dbal->query("SELECT * FROM {$this->tableName} ORDER BY `executed`");
foreach ($result as $row) {
$migration = new Migration;
$migration->id = $row['id'];
$migration->id = (int) $row['id'];
$migration->group = $row['group'];
$migration->filename = $row['file'];
$migration->checksum = $row['checksum'];
$migration->executedAt = $row['executed'];
$migration->executedAt = (is_string($row['executed']) ? new DateTime($row['executed']) : $row['executed']);
$migration->completed = (bool) $row['ready'];

$migrations[] = $migration;
Expand Down
6 changes: 3 additions & 3 deletions src/Drivers/PgSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function insertMigration(Migration $migration)
")
");

$migration->id = $this->dbal->query('SELECT CURRVAL('. $this->primarySequence . ') AS id')[0]['id'];
$migration->id = (int) $this->dbal->query('SELECT CURRVAL('. $this->primarySequence . ') AS id')[0]['id'];
}


Expand All @@ -142,11 +142,11 @@ public function getAllMigrations()
$result = $this->dbal->query("SELECT * FROM {$this->schema}.{$this->tableName} ORDER BY \"executed\"");
foreach ($result as $row) {
$migration = new Migration;
$migration->id = $row['id'];
$migration->id = (int) $row['id'];
$migration->group = $row['group'];
$migration->filename = $row['file'];
$migration->checksum = $row['checksum'];
$migration->executedAt = $row['executed'];
$migration->executedAt = (is_string($row['executed']) ? new DateTime($row['executed']) : $row['executed']);
$migration->completed = (bool) $row['ready'];

$migrations[] = $migration;
Expand Down
17 changes: 17 additions & 0 deletions tests/cases/integration/Runner.FirstRun.init.mysql.doctrine.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS `m` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`group` varchar(100) NOT NULL,
`file` varchar(100) NOT NULL,
`checksum` char(32) NOT NULL,
`executed` datetime NOT NULL,
`ready` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `type_file` (`group`, `file`)
) ENGINE=InnoDB;

INSERT INTO `m` (`group`, `file`, `checksum`, `executed`, `ready`) VALUES ('structures', '001.sql', '%h%', '%a%', '1');
INSERT INTO `m` (`group`, `file`, `checksum`, `executed`, `ready`) VALUES ('structures', '002.sql', '%h%', '%a%', '1');
INSERT INTO `m` (`group`, `file`, `checksum`, `executed`, `ready`) VALUES ('basic-data', '003.sql', '%h%', '%a%', '1');
INSERT INTO `m` (`group`, `file`, `checksum`, `executed`, `ready`) VALUES ('dummy-data', '004.sql', '%h%', '%a%', '1');
INSERT INTO `m` (`group`, `file`, `checksum`, `executed`, `ready`) VALUES ('structures', '005.sql', '%h%', '%a%', '1');

16 changes: 16 additions & 0 deletions tests/cases/integration/Runner.FirstRun.init.pgsql.doctrine.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS "%a%"."m" (
"id" serial4 NOT NULL,
"group" varchar(100) NOT NULL,
"file" varchar(100) NOT NULL,
"checksum" char(32) NOT NULL,
"executed" timestamp NOT NULL,
"ready" boolean NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id"),
CONSTRAINT "type_file" UNIQUE ("group", "file")
) WITH (OIDS=FALSE);

INSERT INTO "%a%"."m" ("group", "file", "checksum", "executed", "ready") VALUES ('structures', '001.sql', '%h%', '%a%', '1');
INSERT INTO "%a%"."m" ("group", "file", "checksum", "executed", "ready") VALUES ('structures', '002.sql', '%h%', '%a%', '1');
INSERT INTO "%a%"."m" ("group", "file", "checksum", "executed", "ready") VALUES ('basic-data', '003.sql', '%h%', '%a%', '1');
INSERT INTO "%a%"."m" ("group", "file", "checksum", "executed", "ready") VALUES ('dummy-data', '004.sql', '%h%', '%a%', '1');
INSERT INTO "%a%"."m" ("group", "file", "checksum", "executed", "ready") VALUES ('structures', '005.sql', '%h%', '%a%', '1');
13 changes: 12 additions & 1 deletion tests/cases/integration/Runner.FirstRun.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ class FirstRunTest extends IntegrationTestCase
{
$options = Tester\Environment::loadData();
$this->runner->run(Runner::MODE_INIT);
Assert::matchFile(__DIR__ . "/Runner.FirstRun.init.$options[driver].txt", $this->printer->out);

$files = [
__DIR__ . "/Runner.FirstRun.init.$options[driver].$options[dbal].txt",
__DIR__ . "/Runner.FirstRun.init.$options[driver].txt",
];

foreach ($files as $file) {
if (is_file($file)) {
Assert::matchFile($file, $this->printer->out);
break;
}
}
}

}
Expand Down
13 changes: 12 additions & 1 deletion tests/cases/integration/Runner.SecondRun.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ class SecondRunTest extends IntegrationTestCase
$options = Tester\Environment::loadData();
$this->driver->loadFile($this->fixtureDir . '/3ok.sql');
$this->runner->run(Runner::MODE_INIT);
Assert::matchFile(__DIR__ . "/Runner.FirstRun.init.$options[driver].txt", $this->printer->out);

$files = [
__DIR__ . "/Runner.FirstRun.init.$options[driver].$options[dbal].txt",
__DIR__ . "/Runner.FirstRun.init.$options[driver].txt",
];

foreach ($files as $file) {
if (is_file($file)) {
Assert::matchFile($file, $this->printer->out);
break;
}
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions tests/inc/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ protected function createDbal($options)
'mysql' => 'mysqli',
'pgsql' => 'pdo_pgsql',
];
new DoctrineAdapter(Doctrine\DBAL\DriverManager::getConnection([
return new DoctrineAdapter(Doctrine\DBAL\DriverManager::getConnection([
'host' => $options['host'],
'username' => $options['username'],
'user' => $options['username'],
'password' => $options['password'],
'database' => $options['database'],
'driver' => $drivers[$options['driver']],
Expand Down

0 comments on commit c89264c

Please sign in to comment.