ZF-43: Unit Tests: First attempt at Zend_Db_Adapter_* unit tests. (TRAC#36)

Description

http://framework.zend.com/developer/ticket/36

We need unit tests for the entire Zend_Db sub tree. The attached patch provides a first cut at testing the Zend_Db_Adapter_Pdo_* sub tree.

I've concentrated more on the structure for the tests and have covered some of the simple cases. (It also picks up the error described in #32).

I would appreciate comments especially on the layout of the test files.

Thanks!

Comments

05/07/06 15:05:02: Modified by rob.nospam@akrabat.com

* attachment db_tests.patch added.

unit tests for Zend_Db_Adapter_Pdo_* v1 05/07/06 15:05:45: Modified by rob.nospam@akrabat.com

Note that the attached patch was created from within the tests subdirectory. 05/07/06 15:42:26: Modified by rob.nospam@akrabat.com

Notes from email sent to fw-general list:

The main test files are tests/Zend/Db/Adapter/Pdo/MssqlTest.php and MysqlTest.php. The classes are Zend_Db_Adapter_Pdo_MssqlTest and Zend_Db_Adapter_Pdo_MysqlTest respectively.

Both these classes inherit from Zend_Db_Adapter_Pdo_Common which is an abstract (empty) class that inherits from Zend_Db_Adapter_Common.

Zend_Db_Adapter_Common is an abstract class that inherits from PHPUnit2_Framework_TestCase. It contains common set up code to create and drop a test table (actual SQL required delegated down to the concrete classes). It also contains tests for functionality that should work regardless of the concrete Adapter used, such as testing insert. 05/30/06 15:46:46: Modified by gavin

When the patch is integrated into the next release, also make sure we have coverage to detect problems like those in #102.

Just a thought... can we not use mock objects here also?

Added the patch from Rob from the old Trac system

Help needed! Volunteers wanted!

We need to update the patch to reflect changes, and expand coverage. Also, test covering resolved issues need to be added.

Correct version of patch from the old Trac system.

The patch didn't seem to apply cleanly for me. I have fixed my trunk so that my patch works again. Will post a patch tomorrow as it's late here!

Woot! Thanks much Rob =)

db_tests2.patch is a diff against revision 845.

I created this patch file using svn diff > db_tests2.patch from the trunk/tests directory, but I can't get it to apply to a clean tree!

This is the result:

ralle@robnb /c/wwwroot/php_include/zf_trunk_tmp/tests $ patch --dry-run < db_tests2.patch
(Stripping trailing CRs from patch.) patching file TestConfiguration.php.dist (Stripping trailing CRs from patch.) patching file AllTests.php Hunk #1 FAILED at 20. Hunk #2 FAILED at 33. Hunk #3 FAILED at 46. 3 out of 3 hunks FAILED -- saving rejects to file AllTests.php.rej (Stripping trailing CRs from patch.) patching file MssqlTest.php (Stripping trailing CRs from patch.) patching file MysqlTest.php (Stripping trailing CRs from patch.) patching file Common.php (Stripping trailing CRs from patch.) patching file Common.php (Stripping trailing CRs from patch.) patching file AllTests.php

It seems like it tries to patch tests/AllTests.php rather than tests/Zend/AllTests.php and I've no idea why.

Any ideas how to get patch.exe to apply this diff or is there another way to do it?

Another attempt at a patch that can be applied... (Thanks Gavin!). This patch is against revision 855.

To apply, copy db_patch3.patch to trunk/ and then from the trunk/ directory, type:

$ patch -p0 < db_patch3.patch

I have just created the unit tests for Pdo_Sqlite, I dont think I can easily create a patch for this since the starting unit tests are not in the repository.

A quick comment on the tests

$suite->addTestSuite('Zend_DbTest');

Is spaced using tabs not spaces.

Can we get this patch checked into trunk so we can start creating patches for futher unit tests?

Fixed the tab issue that Mark Evans noticed.

Thanks guys! Committed (see the FishEye link for details). Ok, lets get your patch next Mark.

Here is the basic tests for sqlite... I have just copied the tests from mysql and modified them to work with sqlite quoting etc.

Committed. Now we need developers to test the tests ;) .. and increase code coverage further.

Would anyone like to work on tests for the other Zend_Db classes (e.g. table, row)?

This was committed months ago, but the issue never resolved.