diff --git a/tests/PdoWrapperTest.php b/tests/PdoWrapperTest.php index 904d95c..d3a2928 100644 --- a/tests/PdoWrapperTest.php +++ b/tests/PdoWrapperTest.php @@ -68,13 +68,33 @@ class PdoWrapperTest extends TestCase public function testFetchField(): void { $id = $this->pdo_wrapper->fetchField('SELECT id FROM test WHERE name = ?', ['two']); - $this->assertEquals(2, $id); + $this->assertSame(2, $id); } public function testFetchFieldReturnsFalseWhenNoResults(): void { $id = $this->pdo_wrapper->fetchField('SELECT id FROM test WHERE id = ?', [999]); - $this->assertFalse($id); + $this->assertSame(false, $id); + } + + public function testFetchFieldReturnsNullWhenColumnIsSqlNull(): void + { + $this->pdo_wrapper->exec('INSERT INTO test (name) VALUES (NULL)'); + $value = $this->pdo_wrapper->fetchField('SELECT name FROM test WHERE name IS NULL'); + $this->assertNull($value); + } + + public function testFetchFieldReturnsZero(): void + { + $value = $this->pdo_wrapper->fetchField('SELECT 0'); + $this->assertSame(0, $value); + } + + public function testFetchFieldReturnsEmptyString(): void + { + $this->pdo_wrapper->exec('INSERT INTO test (name) VALUES ("")'); + $value = $this->pdo_wrapper->fetchField('SELECT name FROM test WHERE name = ?', ['']); + $this->assertSame('', $value); } public function testFetchRow(): void diff --git a/tests/SimplePdoTest.php b/tests/SimplePdoTest.php index ee41697..c4441af 100644 --- a/tests/SimplePdoTest.php +++ b/tests/SimplePdoTest.php @@ -460,18 +460,38 @@ 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]); - $this->assertEquals(1, $id); + $this->assertSame(1, $id); } public function testFetchFieldReturnsFalseWhenNoResults(): void { $value = $this->db->fetchField('SELECT name FROM users WHERE id = ?', [999]); - $this->assertFalse($value); + $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'); + $this->assertSame(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); } }