sebastianbergmann / dbunit

DbUnit port for PHP/PHPUnit.
https://phpunit.de/
Other
225 stars 186 forks source link

DBUnit row ordering during data-table assertions #171

Closed arunjusrut closed 7 years ago

arunjusrut commented 8 years ago

https://phpunit.de/manual/current/en/database.html#database.asserting-the-state-of-a-table

There is an issue in the example given, that does not reflect reality. In the example, three throws are present in the database table. The expectation file contains those three rows as well, so that we can assert against the real table data. The query table is created using "SELECT * FROM guestbook".

Judging from the example, we would assume that asserting two data tables is done without regard to the order of the rows in any of the two data tables. This does not seem to be the case, since my test fails randomly (succeeding at other times), even though the data in database is exactly equal to my expectation file.

The problem, i believe, is the fact that most databases will not return rows in any predictable order, unless an order by clause is explicitly used. So, in short, my expectation records are in a fixed order, while my database returns a result set in no specific order, and DBUnit is sensitive to order when assertions are made.

I cannot seem to understand if this is a bug in dbunit, the documentation is not up-to-date or if i am missing something here. In any case, i have had to used certain hacks (like keeping autoincrements fields to ensure ordering of inserts in database) so that my tests work as expected.

sebastianbergmann commented 7 years ago

Duplicate of #16