tripal / t4d8

This is a temporary repository for Drupal 9 upgrade for Tripal v4. It is meant to house issues related to the upgrade.
GNU General Public License v2.0
1 stars 10 forks source link

Remove auto-creation of Chado in Tests #320

Closed laceysanderson closed 1 year ago

laceysanderson commented 1 year ago

It ended up being a bit more complicated because we need the connection information in helper functions and passing a connection variable in tests causes errors.

As such we now have a ChadoTestTrait->createTestSchema() and ChadoTestTrait->getTestSchema(). You use the create when you want to create a new test schema. This should happen at the beginning of all tests. It is not done in the ChadoTestBrowserBase though because people need to set the init level they want. In most cases you should use either of the following either in the setup in your test or as the first line in the test method.

  1. $this->createTestSchema(ChadoTestBrowserBase::INIT_CHADO_EMPTY);
  2. $this->createTestSchema(ChadoTestBrowserBase::PREPARE_TEST_CHADO);

Then in the helper function you use:

$chado = $this->getTestSchema();

What is this doing / How does this work?

When you use createTestSchema, it creates a new schema and populates it based on the init level you passed in. It also adds the schema name to an array of test schema to drop later. This is what used to happen too... What's different is that now it also assigns the schema name to $this->testSchemaName which is a single string for the current test schema being used.

Then when you call getTestSchema it creates a new ChadoConnection pointing at $this->testSchemaName and thus gives you access to the current test schema -whatever it may be.

NOTE: Even if you are not using the chado connection directly in your test, you still want to call createTestSchema. This method also sets the default chado schema to be the current test schema. Most places in Tripal will use the default chado schema unless it is otherwise specified and thus the test schema is used.

codeclimate[bot] commented 1 year ago

Code Climate has analyzed commit ea3c883b and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 34.3% (0.0% change).

View more on Code Climate.

spficklin commented 1 year ago

This solves a problem and I like it better. It's more clear when programming tests.

spficklin commented 1 year ago

I belive this is a fix for issue #314