PHP Developers Network
http://forums.devnetwork.net/

how to test specific database rows
http://forums.devnetwork.net/viewtopic.php?f=39&t=135087
Page 1 of 1

Author:  kc11 [ Mon Apr 02, 2012 12:24 pm ]
Post subject:  how to test specific database rows

Hi,

I am working on testing a project, using database input. My application takes as input , individual records ( table rows ) from a mysql table. As I've tested, I have gradually debugged the program so that almost all the records result in correct output, but there are still a few that are causing problems. I would to select ONLY the individual records, that are still causing problems for input, or else suspend the program when one of the records of concern is being taken as input. I'd like to do this if possible without hard coding

Is there a way to set a watch in XDEBUG so that the program is run until a certain record is reached , when it can break, allowing me to step through the code.

Another way I've thought of doing this is somehow to sort the mysql table ( in phpmyadmin? ) so that the problem records would be taken as the first input,

Are either of these possible, or is there a better way?

Thanks in advance,

KC

Author:  Celauran [ Sat Jan 20, 2018 7:34 am ]
Post subject:  Re: how to test specific database rows

I advise against using data from a database to populate your tests as a change in any of these rows can cause tests to begin failing for no discernible reason. Sure, it might be more work to transform these into datasets for DBUnit or into data providers for PHPUnit, but you will also end up with higher confidence in your tests.

Author:  Christopher [ Sat Jan 20, 2018 4:23 pm ]
Post subject:  Re: how to test specific database rows

Yes, if you are getting data from a database to test, you should be able to mock that data and run the tests reliably and in any order you want. Celauran's suggestion of datasets or data providers is a good direction.

Author:  VladSun [ Mon Jan 22, 2018 12:29 pm ]
Post subject:  Re: how to test specific database rows

+1 for both oppionions above

Your application should instatinate several classes and one of them is the "DB repository" - i.e. a so-so dummy class responsible only for fetching DB data. The business logic is applied to the data received from this class.

For the "DB" class use DBUnit tests (according to our company terminology these are the "Integration tests") to fully test SQL/ORM etc. code that lies outside your business domain boundaries.

And for the business classes - provide a mocked data and test "DBless".

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/