Skip to content

Commit

Permalink
AddEntityTest - Update for dynamic SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Apr 19, 2024
1 parent 5223b20 commit 87fc12c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
32 changes: 14 additions & 18 deletions tests/e2e/AddEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class AddEntityTest extends \PHPUnit\Framework\TestCase {
public function setUp(): void {
chdir(static::getWorkspacePath());
static::cleanDir(static::getKey());
$this->civixGenerateModule(static::getKey());
$this->civixGenerateModule(static::getKey(), [
'--compatibility' => '5.69',
]);
chdir(static::getKey());

$this->assertFileGlobs([
Expand All @@ -44,6 +46,7 @@ public function testAddEntity(): void {
]);
$this->assertFileGlobs(array_fill_keys($this->entityFiles, 0));

$this->civixGenerateUpgrader();
$this->civixGenerateEntity('Bread');
$this->civixGenerateEntity('Sandwich');
$this->civixGenerateEntity('Meal');
Expand All @@ -57,26 +60,19 @@ public function testAddEntity(): void {
$this->civixGenerateEntityBoilerplate();

$this->assertFileGlobs([
'sql/auto_install.sql' => 1,
// No longer use static files
'sql/auto_install.sql' => 0,
]);
$this->assertFileGlobs(array_fill_keys($this->entityFiles, 1));

$install = $this->grepLines(';CREATE TABLE;', $this->getExtPath('sql/auto_install.sql'));
$uninstall = $this->grepLines(';DROP TABLE;', $this->getExtPath('sql/auto_uninstall.sql'));

$this->assertEquals([
'CREATE TABLE `civicrm_flour` (',
'CREATE TABLE `civicrm_bread` (',
'CREATE TABLE `civicrm_sandwich` (',
'CREATE TABLE `civicrm_meal` (',
], $install);

$this->assertEquals([
'DROP TABLE IF EXISTS `civicrm_meal`;',
'DROP TABLE IF EXISTS `civicrm_sandwich`;',
'DROP TABLE IF EXISTS `civicrm_bread`;',
'DROP TABLE IF EXISTS `civicrm_flour`;',
], $uninstall);
$this->assertEquals('CiviMix\\Schema\\CivixAddentity\\AutomaticUpgrader', trim($this->civixInfoGet('upgrader')->getDisplay()));
$civixPhpFile = $this->getExtPath('civix_addentity.civix.php');
$content = file_get_contents($civixPhpFile);
$this->assertStringSequence([
'($GLOBALS[\'_PathLoad\'][0] ?? require __DIR__ . \'/mixin/lib/pathload-0.php\');',
'pathload()->addSearchDir(__DIR__ . \'/mixin/lib\');',
' pathload()->loadPackage(\'civimix-schema@5\', TRUE);'
], $content);
}

private function grepLines(string $pattern, string $file): array {
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/CivixProjectTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public function civixGenerateService(string $name, array $options = []): Command
return $tester;
}

public function civixGenerateUpgrader(array $options = []): CommandTester {
$tester = static::civix('generate:upgrader');
$tester->execute($options);
if ($tester->getStatusCode() !== 0) {
throw new \RuntimeException(sprintf("Failed to generate upgrader (%s)", static::getKey()));
}
return $tester;
}

/**
* Get a value from "info.xml" by calling "civix info:get"
*
Expand Down

0 comments on commit 87fc12c

Please sign in to comment.