Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running unit tests don't accidentally overwrite your db #24652

Merged
merged 1 commit into from
Oct 15, 2022

Conversation

demeritcowboy
Copy link
Contributor

Overview

Update civicrm.settings.php to abort instead of falling back your "real" db.

Before

As currently written, this if-block will fall back to your "real" db if for whatever reason $GLOBALS['_CV']['TEST_DB_DSN'] isn't set, potentially causing the test sytem to overwrite the data.

  if (CIVICRM_UF === 'UnitTests' && isset($GLOBALS['_CV']['TEST_DB_DSN'])) {
    define('CIVICRM_DSN', $GLOBALS['_CV']['TEST_DB_DSN']);
   }
   else {
     define('CIVICRM_DSN', 'mysql://%%dbUser%%:%%dbPass%%@%%dbHost%%/%%dbName%%?new_link=true%%dbSSL%%');

After

Aborts instead.

Technical Details

I'm not sure why $GLOBALS['_CV']['TEST_DB_DSN'] wasn't set in my case, possibly a windows+cv+drupal8 situation failing to find some path - I don't usually run core tests with that combo. So the actual problem might be elsewhere but I'm thinking better to abort so you can then go search for the problem rather than overwrite the db.

Comments

There might be a legitimate configuration where the expectation is it uses the value in civicrm.settings.php instead of the test db when it's blank, but I'm not sure what that would be.

@civibot
Copy link

civibot bot commented Sep 30, 2022

(Standard links)

@civibot civibot bot added the master label Sep 30, 2022
@demeritcowboy
Copy link
Contributor Author

In my case cv couldn't find what it needed because on windows you can have a slash mismatch or case-sensitive mismatch between CIVICRM_SETTINGS and the array key in ~/.cv.json, so when it hits https://github.com/civicrm/cv/blob/master/src/SiteConfigReader.php#L67 it finds no match. But I still think this PR is a good idea.

@colemanw
Copy link
Member

Makes sense and doesn't affect our testing CI. I pulled it down and confirmed tests still run locally.

@colemanw colemanw merged commit f1bdca1 into civicrm:master Oct 15, 2022
@demeritcowboy
Copy link
Contributor Author

Thanks!

@demeritcowboy demeritcowboy deleted the noset branch October 15, 2022 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants