3

I'm using headless phpunit tests. I noticed that the first time I do this it pauses and says about installing schema for xxxx - a test database.

If you break stuff enough, you can end up with a corrupted/no-good test CRM database. How do you get a fresh one back?

I tried dropping the test database, but that just caused errors.

Thanks.

5

ah-ha!

In your test class edit the setUpHeadless() method which might look at first like this:

  public function setUpHeadless() {                                                                                                                                                                                                           
    // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
    // See: https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md
    return \Civi\Test::headless()
      ->installMe(__DIR__)
      ->apply();

But pass TRUE to apply(), ie

  public function setUpHeadless() {                                                                                                                                                                                                           
    // Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
    // See: https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md
    return \Civi\Test::headless()
      ->installMe(__DIR__)
      ->apply(TRUE);

Ta-daa! And now your tests will run super slow as the schema will be reinstalled every time. But helps you out of a spot, and you can of course remove that param.

0

It's also worth noting that if you're using civicrm-buildkit to create your test sites (highly recommended) you can also rebuild a site with civibuild reinstall.

  • Using civi-buildkit is the only way I've gotten tests to run at all, as required files are not present in standards installs. I'm not sure a site rebuild would result in a schema rebuild (?) since I don't think any of the data used to create the comparison hash would have changed. I think I tried that once. – artfulrobot Oct 18 '17 at 6:31
  • I didn't realize you needed a schema rebuild - for that you can always run bin/regen.sh, then do the reinstall. – Jon G - Megaphone Tech Oct 18 '17 at 6:38
  • I think what you're suggesting will rebuild the main schema of the civi-buildkit site. When you run headless (the default type) tests a separate new database is created; the original buildkit one is supposedly untouched. I'll check out that command though, thanks – artfulrobot Oct 18 '17 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.