Add Db module alternative that integrates with PHPUnit's DbUnit extension #650

Closed
elazar opened this Issue Nov 4, 2013 · 3 comments

3 participants

@elazar

PHPUnit has a DbUnit extension that provides much of the same functionality as the existing Codeception Db module. The difference is that it's invoked through code rather than configuration, enabling the developer to implement things like connections to multiple databases (see #301) or varying data sets between tests. Codeception could potentially support a module apart form Db that wraps DbUnit to offer this alternative functionality.

Example use case: I'm currently writing functional tests for a REST API backed by a MySQL database. Only being allowed one data set can make it difficult to iteratively develop tests for an existing codebase. For example, in testing search functionality where I want to perform an assertion against record counts to ensure that I got back the expected number of results, adding additional records for new tests can cause such assertions to fail.

Codeception's own documentation maintains that tests should not affect each other, yet only allows for one data set for all tests; these two situations seem to be in contradiction or at best in conflict with each other. Being able to have a separate data set per test would remove this difficulty and make tests more atomic.

Disclaimer: I am currently a maintainer of DbUnit, having received merge rights following my presentation on the subject at SunshinePHP 2013.

@DavertMik
Codeception Testing Framework member

Sure, Codeception's Db module is very basic, and designed to be easy to start. It can be extended, yet, it has its limitations. The example you provided is the case yet not supported by Db module.

Contrary DbUnit looks like a complete enterprise solution, but it is really really hard to get into it, and manage its datasets. But there are some things I dislike there:

  • managing xml datasets is painful
  • even you don't use xml - managing all kind of fixtures are painful too.
  • creating connection, setting up db unit, is quite a hard task itself.
  • .... too complex.

Ideally I'd like to have a solution that takes best from 2 projects. But without fixtures. I'd like to get them replaced with factories: datasets generated with tool like Faker.

If you think you can bring cool ideas to improve Db module, please share them. That would be great.

As for DbUnit module, it can be stored in 3rd party repo, like extension and be the alternative for Db. I won't include it into core repo, because I can't write a proper documentation for it and help solving its issues.

@javigomez

The link in the previous comment is wrong, it should link to http://codeception.com/addons

@DavertMik
Codeception Testing Framework member

Yes, the 3rd-party module is welcome.

@DavertMik DavertMik closed this Nov 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment