Merge pull request #22164 from eileenmcnaughton/parent
[civicrm-core.git] / Civi / Test / CiviEnvBuilder.php
index 767d34033a814f3de3072fabb884d91bb149f9d8..8bce9d1fbf5e6a57d03e389ee92330d33b6555b8 100644 (file)
@@ -2,6 +2,7 @@
 namespace Civi\Test;
 
 use Civi\Test\CiviEnvBuilder\CallbackStep;
+use Civi\Test\CiviEnvBuilder\CoreSchemaStep;
 use Civi\Test\CiviEnvBuilder\ExtensionsStep;
 use Civi\Test\CiviEnvBuilder\SqlFileStep;
 use Civi\Test\CiviEnvBuilder\SqlStep;
@@ -41,6 +42,15 @@ class CiviEnvBuilder {
     return $this->addStep(new CallbackStep($callback, $signature));
   }
 
+  /**
+   * Generate the core SQL tables.
+   *
+   * @return \Civi\Test\CiviEnvBuilder
+   */
+  public function coreSchema() {
+    return $this->addStep(new CoreSchemaStep());
+  }
+
   public function sql($sql) {
     return $this->addStep(new SqlStep($sql));
   }
@@ -168,24 +178,26 @@ class CiviEnvBuilder {
    * @return CiviEnvBuilder
    */
   public function apply($force = FALSE) {
-    $dbName = \Civi\Test::dsn('database');
-    $query = "USE {$dbName};"
-      . "CREATE TABLE IF NOT EXISTS civitest_revs (name VARCHAR(64) PRIMARY KEY, rev VARCHAR(64));";
+    return \Civi\Test::asPreInstall(function() use ($force) {
+      $dbName = \Civi\Test::dsn('database');
+      $query = "USE {$dbName};"
+        . "CREATE TABLE IF NOT EXISTS civitest_revs (name VARCHAR(64) PRIMARY KEY, rev VARCHAR(64));";
 
-    if (\Civi\Test::execute($query) === FALSE) {
-      throw new \RuntimeException("Failed to flag schema version: $query");
-    }
+      if (\Civi\Test::execute($query) === FALSE) {
+        throw new \RuntimeException("Failed to flag schema version: $query");
+      }
 
-    $this->assertValid();
+      $this->assertValid();
 
-    if (!$force && $this->getSavedSignature() === $this->getTargetSignature()) {
+      if (!$force && $this->getSavedSignature() === $this->getTargetSignature()) {
+        return $this;
+      }
+      foreach ($this->steps as $step) {
+        $step->run($this);
+      }
+      $this->setSavedSignature($this->getTargetSignature());
       return $this;
-    }
-    foreach ($this->steps as $step) {
-      $step->run($this);
-    }
-    $this->setSavedSignature($this->getTargetSignature());
-    return $this;
+    });
   }
 
   /**