1

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
freshp
  • 525
  • 5
  • 20

2 Answers2

2

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.

cweiske
  • 30,033
  • 14
  • 133
  • 194
0

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

Community
  • 1
  • 1
freshp
  • 525
  • 5
  • 20