IMP-specific PHPUnit Directions

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

We're collecting questions from today's sprint in hopes of getting documentation together for future work.

Where do I put my tests?

Add tests to the exisiting test files.

For MigrateExecutable.php, add to:

  • core/modules/migrate/tests/Drupal/migrate/Test/MigrateExecutableTest.php

For Sql.php, add to

  • ./core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlIdMapTest.php

What does the getMock function do? What's the high-level idea of the function and how do I know what to pass to it?

What are the steps that any given test much perform so that it's considered a complete and functional test?

Ideally, our tests would cover every possible code path, every line of code would get fired (if the code makes N decisions via if / ? then you need to write 2N tests). Also, just one test covering the most frequent case is better than no test.

What does TestSqlIdMap class do?

So, it looks like TestSqlIdMap mocks the Sql object, passing a mock DB (with optional hard-coded contents)

A few more tips:

If there is a property something the user can configure, it goes on the migration entity. A few were left on the MigrateExecutable. For example change $this->timeThreshold to $this->migration->get('timeThreshold') and add a public timeThreshold property to the migration entity.

If there is a property the test should be able to set, then add a setter on the TestMigrateExecutable class. You can also use this class to make a method public:

<?php
public function maxExecTime() {
  return
parent::maxExecTime();
}
?>

to make maxExecTime() accessible to the test. We do not use reflection.