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

ENH Let unit tests manipulate the DB before loading fixtures #11182

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Mar 20, 2024

Description

Fixtures in unit tests can be set up using an explicit table name - but there's no way (that I can see) to actually create the table in the time between the test DB being created and fixtures being loaded.

This PR adds a way for tests to do that.

See silverstripe/silverstripe-linkfield#253 for an example of how this works.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me. I would probably add a comment that says the method is to be overridden in custom tests otherwise it feels like it can just be removed with the // no-op body.

@GuySartorelli
Copy link
Member Author

GuySartorelli commented Mar 20, 2024

Added a note that it is intended to be overridden by subclasses. There's also an associated docs PR now linked in the main issue.

@GuySartorelli GuySartorelli force-pushed the pulls/5/manipulate-db-before-fixtures branch from daed16c to 72c963e Compare March 20, 2024 22:23
@GuySartorelli GuySartorelli force-pushed the pulls/5/manipulate-db-before-fixtures branch from 72c963e to f64fdc7 Compare March 26, 2024 21:14
@GuySartorelli
Copy link
Member Author

rebased so the installer CI run was happy (see link in issue)

@michalkleiner
Copy link
Contributor

Merge when needed.

@emteknetnz emteknetnz merged commit b442d9d into silverstripe:5 Apr 1, 2024
15 checks passed
@emteknetnz emteknetnz deleted the pulls/5/manipulate-db-before-fixtures branch April 1, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants