Question

I search for a way to load test-data to a MySQL in my phpunit testcase. I use typo3 4.5 and want to test my pages-override and some functions in my testcase. I don't want to create all models ever and ever by hand, and would like to load a test-db and some sql-file for each test. Is this possible?

Was it helpful?

Solution 2

I resolved this problem by loading a complete testdatabase in my setup method. It works for me. For some inserts i will try to use

 function setUp() { $this->db->exec("BEGIN"); }
 function tearDown() { $this->db->exec("ROLLBACK"); }

like here

OTHER TIPS

In the tests for our TYPO3 extensions, we run $GLOBALS['TYPO3_DB']->exec_INSERTquery() calls with test data in setUp(). tearDown() makes exec_DELETEquery() calls.

Test data get names like "unittest-FOO", so that we can delete all "unittest-%" entries when cleaning up.

Alternatively, you can use the phpunit extension for TYPO3 - it adds a column to each table that indicates if a record is a test datum or not. Cleaning up afterwards is easy then.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top