Merge pull request #20951 from eileenmcnaughton/act
[civicrm-core.git] / Civi / Test / CiviEnvBuilder / CoreSchemaStep.php
1 <?php
2 namespace Civi\Test\CiviEnvBuilder;
3
4 /**
5 * Class CoreSchemaStep
6 * @package Civi\Test\CiviEnvBuilder
7 *
8 * An initialization step which loads the core SQL schema.
9 *
10 * Note that the computation of the schema is cached for the duration of
11 * the PHP process (\Civi\Test::$statics).
12 */
13 class CoreSchemaStep implements StepInterface {
14
15 /**
16 * @return array
17 * - digest: string
18 * - content: string
19 */
20 public function getSql() {
21 if (!isset(\Civi\Test::$statics['core_schema_sql'])) {
22 $schema = new \CRM_Core_CodeGen_Schema(\Civi\Test::codeGen());
23 $files = $schema->generateCreateSql();
24 \Civi\Test::$statics['core_schema_sql'] = [
25 'digest' => md5($files['civicrm.mysql']),
26 'content' => $files['civicrm.mysql'],
27 ];
28 }
29 return \Civi\Test::$statics['core_schema_sql'];
30 }
31
32 public function getSig() {
33 return $this->getSql()['digest'];
34 }
35
36 public function isValid() {
37 return TRUE;
38 }
39
40 /**
41 * @param \Civi\Test\CiviEnvBuilder $ctx
42 */
43 public function run($ctx) {
44 $sql = $this->getSql();
45 if (\Civi\Test::execute($sql['content']) === FALSE) {
46 throw new \RuntimeException("Cannot execute SQL");
47 }
48 }
49
50 }