Civi\Test - Allow `headless()->apply()` (etc) to execute without setup.sh
authorTim Otten <totten@civicrm.org>
Mon, 27 Jan 2020 23:59:41 +0000 (15:59 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 28 Jan 2020 22:22:22 +0000 (14:22 -0800)
commitc0d844184af9edd9c67eb419460e319659089605
tree7698c5f4db0eab1dff95e497618cea28e8ac082f
parent9d114ab61c840acd8257734ff766582f4bb6d05e
Civi\Test - Allow `headless()->apply()` (etc) to execute without setup.sh

Before
------

If you have a copy of the `git` codebase and wish to run any of the headless
test suites, you *must* run `setup.sh` aka `GenCode` beforehand.

This is because certain files - `sql/civicrm.mysql` and
`sql/civicrm_data.mysql` - are used in the headless suite.  As large
auto-generated files, they are not provided in git.

After
-----

The files `sql/civicrm.mysql` and `sql/civicrm_data.mysql` are no longer
required by the test suite -- the headless tests will directly use the
`GenCode` classes to produce the needful.

Comments
--------

The general thrust of this commit is to find spots which read an SQL file, e.g.

```php
\Civi\Test::execute(file_get_contents("foobar.mysql"));
```

and instead call the generator for that file, e.g.:

```php
$schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen());
$result = $schema->generateFooBar();
\Civi\Test::execute($result['foobar.mysql']);
});
```

In doing so, we incorporate a couple tricks:

* The SQL content is cached for the duration of the test-run (`Civi\Test::$statics`).
  Generating the SQL is not super expensive... but `Civi\Test::headless()->...apply()`
  may be called thousands of times, so it could add-up. Just cache it.
* Most of the `generateFooBar()` functions depend in some fashion on `ts()`. This
  commit depends on a preceding commit to make `ts()` more amenable to execution
  during early stages of the test.
    * Related discussion: https://chat.civicrm.org/civicrm/pl/ehohytqkf7bd5prg9w75dq4qqw
CRM/Core/CodeGen/Main.php
Civi/Test.php
Civi/Test/CiviEnvBuilder.php
Civi/Test/CiviEnvBuilder/CoreSchemaStep.php [new file with mode: 0644]
Civi/Test/Data.php