add test case for database_interface.class.php and DBI class #407

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@adamgsoc2013
Contributor

No description provided.

@nijel nijel commented on the diff Jun 9, 2013
test/libraries/database_interface_test.php
+ */
+ function testRealMultiQuery()
+ {
+ $this->assertFalse($GLOBALS['dbi']->tryMultiQuery('SELECT 1'));
+ }
+
+ /**
+ * Simple test for dataSeek
+ *
+ * This relies on dummy driver internals
+ *
+ * @return void
+ */
+ function testDataSeek()
+ {
+ $this->assertFalse($GLOBALS['dbi']->dataSeek(0, 2));
@nijel
nijel Jun 9, 2013 Member

dataSeek makes sense only after executing query. You should execute a query, get result identifier and use it then.

@adamgsoc2013
adamgsoc2013 Jun 9, 2013 Contributor

Hi Michal, In fact, in this class we just test for Dummy driver, which the data is faked by us. Look at this line: https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/database_interface.inc.php#L18

so for dataSeek function, it just check the result: https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/dbi/DBIDummy.class.php#L439

I am doing the mysql driver and mysqli driver, which must be do it after executing query. I will at a new test class database_interface_mysql_test.php

@nijel
nijel Jun 10, 2013 Member

I know how dummy driver behaves, but when you want to test database interface, you should do real tests and not depend on dummy driver internals. Maybe I should change it not to provide stable results to prevent these kinds of misusing it.

@nijel nijel commented on the diff Jun 9, 2013
test/libraries/database_interface_test.php
+ * @return void
+ */
+ function testDataSeek()
+ {
+ $this->assertFalse($GLOBALS['dbi']->dataSeek(0, 2));
+ $this->assertTrue($GLOBALS['dbi']->dataSeek(0, 0));
+ }
+
+ /**
+ * Simple test for empty methods
+ *
+ * This relies on dummy driver internals
+ *
+ * @return void
+ */
+ function testEmptyMethod()
@nijel
nijel Jun 9, 2013 Member

What is benefit of testing empty methods?

@adamgsoc2013
adamgsoc2013 Jun 9, 2013 Contributor

we can think of it placeholder when we add logic for Dummy class. thanks

@nijel nijel commented on the diff Jun 9, 2013
test/libraries/database_interface_test.php
+ $this->assertEquals(array(), $GLOBALS['dbi']->getFieldsMeta(1));
+ $this->assertEquals(-1, $GLOBALS['dbi']->fieldLen(1, 0));
+ $this->assertEquals('', $GLOBALS['dbi']->fieldName(1, 0));
+ $this->assertEquals('', $GLOBALS['dbi']->fieldFlags(1, 0));
+ }
+
+ /**
+ * Simple test for numFields
+ *
+ * This relies on dummy driver internals
+ *
+ * @return void
+ */
+ function testNumFields()
+ {
+ $this->assertEquals(0, $GLOBALS['dbi']->numFields(0));
@nijel
nijel Jun 9, 2013 Member

Same here as with dataSeek - you should use resource identifier returned by tryQuery and not relying on internal numbering of the driver.

@adamgsoc2013
adamgsoc2013 Jun 9, 2013 Contributor

look at https://github.com/phpmyadmin/phpmyadmin/blob/master/libraries/dbi/DBIDummy.class.php#L601

It is just check the faked data. thanks

we should do it like the way your mentioned when testing mysql driver/

@madhuracj
Member

You seem to test the implementation of DBIDummy.class.php here. So it better go inside some other file, not test/libraries/database_interface_test.php. And if you are testing the methods of DatabaseInterface class, it's better to mock the database extension object so you can control how it behaves.

@madhuracj
Member

And when you are testing DatabaseInterface class, create a fresh object of it rather than using $GLOBALS['dbi'].

@adamgsoc2013
Contributor

Hi madhuracj, you are right. In fact, I think DBIDummy.class.php is mocked data for test database driver behavior.

I will use database_interface_test.php for testing DBIDummy.class.php for the base functions
used database_interface_mysql_test.php for testing mysql driver
used database_interface_drizzle_test.php for testing drizzledriver
used database_interface_mysqli_test.php for testing mysqli driver

please advise, thanks

@madhuracj
Member

Well the methods in DBIDummy.class.php do sort of mocking. But the problem with that is, it always return the stipulated values and for a particular test you might want a method return something else. So IMO, it is better to mock the DB extension when you are testing the methods in PMA_DatabaseInterface class.

I'd use
PMA_DatabaseInterface_test.php to test PMA_DatabaseInterface class,
PMA_DBI_Mysql_test.php to test PMA_DBI_Mysql class,
PMA_DBI_Mysqli_test.php to test PMA_DBI_Mysqli class and
PMA_DBI_Drizzle_test.php to test PMA_DBI_Drizzle class

I'm not sure how useful it is to test the Dummy driver.

@adamgsoc2013
Contributor

OK. I will think more about DDI testing. close this request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment