Fix PDO boolean handling

This commit is contained in:
Bartek Fabiszewski 2020-05-21 18:08:00 +02:00
parent 0e79e907b5
commit 3fd5171e2b
2 changed files with 8 additions and 12 deletions

View File

@ -42,7 +42,7 @@ class MigrateTest extends UloggerDatabaseTestCase {
$this->setOutputCallback(static function() {});
$ret = updateSchemas();
$this->resetConnection();
$this->assertEquals(true, $ret, "Function updateSchemas() failed");
$this->assertTrue($ret, "Function updateSchemas() failed");
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
$this->assertEquals(1, $this->getConnection()->getRowCount("positions"), "Wrong row count");
@ -56,14 +56,10 @@ class MigrateTest extends UloggerDatabaseTestCase {
$this->loadDataSet("fixture_non_admin.xml");
$this->setOutputCallback(static function() {});
$ret = updateConfig(dirname(__DIR__) . "/fixtures/config_0_6.php");
$this->assertEquals(true, $ret, "Function updateConfig() failed");
$this->assertTrue($ret, "Function updateConfig() failed");
// admin user imported from config file
$expected = [ "admin" => 1 ];
$actual = $this->getConnection()->createQueryTable(
"admin",
"SELECT admin FROM users WHERE login = 'admin'"
);
$this->assertTableContains($expected, $actual, "Wrong actual table data");
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
$this->assertTrue((bool) $this->pdoGetColumn("SELECT admin FROM users WHERE login = 'admin'"), "User should be admin");
// settings imported from config file
$expected = [ "config" => [
["name" => "color_extra", "value" => "s:7:\"#cccccc\";"], // default
@ -108,13 +104,13 @@ class MigrateTest extends UloggerDatabaseTestCase {
fwrite($yes, "yes");
$ret = waitForUser(stream_get_meta_data($yes)['uri']);
fclose($yes);
$this->assertEquals(true, $ret, "Wrong return status");
$this->assertTrue($ret, "Wrong return status");
$no = tmpfile();
fwrite($no, "no");
$ret = waitForUser(stream_get_meta_data($no)['uri']);
fclose($no);
$this->assertEquals(false, $ret, "Wrong return status");
$this->assertFalse($ret, "Wrong return status");
}
/**

View File

@ -113,9 +113,9 @@ function updateConfig($path = ROOT_DIR . "/config.php") {
if (isset($admin_user) && !empty($admin_user)) {
try {
echo "Setting user $admin_user as admin" . PHP_EOL;
$query = "UPDATE " . uDb::getInstance()->table('users') . " SET admin = TRUE WHERE login = ?";
$query = "UPDATE " . uDb::getInstance()->table('users') . " SET admin = ? WHERE login = ?";
$stmt = uDb::getInstance()->prepare($query);
$stmt->execute([ $admin_user ]);
$stmt->execute([ 1, $admin_user ]);
if ($stmt->rowCount() === 0) {
echo "User $admin_user not found in database table" . PHP_EOL;
echo "Set your admin user manually in users table" . PHP_EOL;