phpunit for local plugin db tests: moodle_database::insert_record_raw() no fields found

phpunit for local plugin db tests: moodle_database::insert_record_raw() no fields found

by Michael Beauregard -
Number of replies: 1

I'm writing my first local plugin and things are going well except for my latest unit test which is trying to test DB access to the plugin's table. I suspect that this is a test environment setup issue, but I really have no idea what to do about it. When I run my tests, I currently get the following error:

coding_exception: Coding error detected, it must be fixed by a programmer: moodle_database::insert_record_raw() no fields found.

/Applications/MAMP/htdocs/moodle25/lib/dml/mysqli_native_moodle_database.php:1075
/Applications/MAMP/htdocs/moodle25/lib/dml/mysqli_native_moodle_database.php:1132

...

The test dataroot and table prefix are configured as:

$CFG->phpunit_dataroot = '~/moodle/phpunit_data/moodle25';
$CFG->phpunit_prefix = 'phpu_';

Printing out objects in various places shows me that the plugin's table does not appear to exist in the database. Is there something I need to do to create the test database instance or is that created/destroyed on each test run? The plugin's table does exist in the database so I know that the install.xml is at least correct. I've read and re-read all of the phpunit testing related pages and don't know what I'm missing.

Any help would be fantastic.

Thanks!

Michael

 

Average of ratings: -
In reply to Michael Beauregard

Re: phpunit for local plugin db tests: moodle_database::insert_record_raw() no fields found

by Michael Beauregard -

I spent quite a bit of time trying to figure out what is going on here. I finally gave up and created a brand new moodle dev environment (from the MAMP package), added my plugin, then initialized the phpunit test environment (using these instructions: http://docs.moodle.org/dev/PHPUnit_installation_in_OS_X#Install_PHPUnit) and now my test runs correctly.

Maybe it's a bug. Maybe it was because I added my plugin and table *after* I originally initialized the test env. Note that rerunning the 'php admin/tool/phpunit/cli/init.php' command did not help.