X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=testing%2FDBTest.php;fp=testing%2FDBTest.php;h=e626eddce61f1273a098fa2217bf3040d84fd68c;hb=6855525e48fad5de270500a5445c4f4ff85d8bda;hp=0000000000000000000000000000000000000000;hpb=e69709aa8ee6108a1197e46b45367ba8dab55a52;p=diogenes.git diff --git a/testing/DBTest.php b/testing/DBTest.php new file mode 100644 index 0000000..e626edd --- /dev/null +++ b/testing/DBTest.php @@ -0,0 +1,96 @@ +getMessage()."\n".$DB->getUserInfo()."\n"); + } + + $this->assertEquals($tables, $DB->getCol('show tables')); + } +} + +class DiogenesDatabaseTest extends PHPUnit_TestCase +{ + function testConstructor() + { + $DB = new DiogenesDatabase('localhost', 'test', 'test', ''); + + $this->assertTrue(is_object($DB)); + } + + function testErrors() + { + $db = new DiogenesDatabase('tst', 'localhost', 'test', ''); + + $this->assertTrue($db->err()); + $this->assertEquals(1049, $db->errno()); + $this->assertEquals("Unknown database 'tst'", $db->error()); + + $db->ResetError(); + $this->assertFalse($db->err()); + $this->assertEquals(0, $db->errno()); + $this->assertEquals('', $db->error()); + + } + + function testMoreErrors() + { + $db = new DiogenesDatabase('test', 'localhost', 'test', ''); + + $this->assertFalse($db->err(), "Should be no error"); + + $db->query("SLECT"); + + $this->assertTrue($db->err(), "Should be error"); + $this->assertEquals(1064, $db->errno()); + $this->assertEquals("You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SLECT' at line 1", $db->error()); + $this->assertEquals("SLECT", $db->errinfo()); + + $db->ResetError(); + $this->assertEquals('', $db->errinfo()); + } +}