4

Hey, Im new to the whole PHPUnit and would like to test my code against a database, from reading all the stuff on the phpunit.de, it talks about a seed.xml file.

Can someone just clarify, do i need to create this dataset myself using a mysqldump command, or does it create it for me at the beginning of the test?

Many thanks in advance

phpNutt
  • 1,529
  • 7
  • 23
  • 40

1 Answers1

4

I am just now researching this myself and came across this blog post:

http://matthewturland.com/2010/01/04/database-testing-with-phpunit-and-mysql/

So if you choose to accept the PHPUnit >= 3.5.0 requirements, you can use

mysqldump --xml -t -u username -p database

to create seed.xml and then load it as a dataset for DBUnit with

$dataSet = $this->createMySQLXMLDataSet('/path/to/seed.xml');
Stijn Hoop
  • 459
  • 4
  • 12
  • I've done this and get error messages like `RuntimeException: Input is not proper UTF-8, indicate encoding ! Bytes: 0xE4 0x6B 0x6F 0x77 PCDATA invalid Char value 25 PCDATA invalid Char value 20 PCDATA invalid Char value 12 PCDATA invalid Char value 31 Premature end of data in tag field line 40095 Premature end of data in tag row line 40091 Premature end of data in tag table_data line 40090 Premature end of data in tag database line 3 Premature end of data in tag mysqldump line 2` – ashgromnies Mar 18 '14 at 16:57
  • It sounds like your dump file is not valid UTF-8 encoded. Check the encoding of your MySQL database. Some googling leads me to believe that you can convert the dump file if you know the source encoding by using the iconv utility, see http://docs.moodle.org/24/en/Converting_files_to_UTF-8 But I expect things will be a lot easier if you convert your database to use UTF-8 first. – Stijn Hoop Mar 21 '14 at 09:20