|
|
|
|
@ -460,12 +460,40 @@ class SimplePdoTest extends TestCase
|
|
|
|
|
public function testFetchFieldReturnsValue(): void
|
|
|
|
|
{
|
|
|
|
|
$name = $this->db->fetchField('SELECT name FROM users WHERE id = ?', [1]);
|
|
|
|
|
$this->assertEquals('John', $name);
|
|
|
|
|
$this->assertSame('John', $name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFetchFieldReturnsFirstColumn(): void
|
|
|
|
|
{
|
|
|
|
|
$id = $this->db->fetchField('SELECT id, name FROM users WHERE id = ?', [1]);
|
|
|
|
|
// PDO SQLite may return numeric strings on PHP < 8.1
|
|
|
|
|
$this->assertEquals(1, $id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFetchFieldReturnsFalseWhenNoResults(): void
|
|
|
|
|
{
|
|
|
|
|
$value = $this->db->fetchField('SELECT name FROM users WHERE id = ?', [999]);
|
|
|
|
|
$this->assertSame(false, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFetchFieldReturnsNullWhenColumnIsSqlNull(): void
|
|
|
|
|
{
|
|
|
|
|
$this->db->exec('INSERT INTO users (name, email) VALUES (NULL, "null@example.com")');
|
|
|
|
|
$value = $this->db->fetchField('SELECT name FROM users WHERE email = ?', ['null@example.com']);
|
|
|
|
|
$this->assertNull($value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFetchFieldReturnsZero(): void
|
|
|
|
|
{
|
|
|
|
|
$value = $this->db->fetchField('SELECT 0');
|
|
|
|
|
// PDO SQLite may return '0' on PHP < 8.1
|
|
|
|
|
$this->assertEquals(0, $value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFetchFieldReturnsEmptyString(): void
|
|
|
|
|
{
|
|
|
|
|
$this->db->exec('INSERT INTO users (name, email) VALUES ("", "empty@example.com")');
|
|
|
|
|
$value = $this->db->fetchField('SELECT name FROM users WHERE email = ?', ['empty@example.com']);
|
|
|
|
|
$this->assertSame('', $value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|