Skip to content

Commit

Permalink
BootCommand - Add support for --level=cms-full
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Mar 8, 2023
1 parent 72b38d1 commit 248bc8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/cv
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ $autoloaders = array(
foreach ($autoloaders as $autoloader) {
if (file_exists($autoloader)) {
require_once $autoloader;
define('CV_AUTOLOAD', $autoloader);
$found = 1;
break;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Command/BootCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Civi\Cv\Command;

use Civi\Cv\CmsBootstrap;
use Civi\Cv\Util\BootTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -36,6 +37,15 @@ protected function execute(InputInterface $input, OutputInterface $output) {
. '\CRM_Utils_System::loadBootStrap(array(), FALSE);';
break;

case 'cms-full':
$instance = \Civi\Cv\CmsBootstrap::singleton();
$instanceExpr = '\\' . get_class($instance) . '::singleton()';
$code = '';
$code .= sprintf("require_once %s;\n", var_export(CV_AUTOLOAD, TRUE));
$code .= sprintf("%s->addOptions(%s);\n", $instanceExpr, var_export($instance->getOptions(), TRUE));
$code .= sprintf("%s->bootCms()->bootCivi();\n", $instanceExpr);
break;

case 'none':
break;

Expand Down
16 changes: 14 additions & 2 deletions tests/Command/BootCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function setUp(): void {
parent::setUp();
}

public function testBootDefault() {
$phpBoot = Process::runOk($this->cv("php:boot"));
public function testBootFull() {
$phpBoot = Process::runOk($this->cv("php:boot --level=full"));
$this->assertRegExp(';CIVICRM_SETTINGS_PATH;', $phpBoot->getOutput());

$helloPhp = escapeshellarg($phpBoot->getOutput()
Expand All @@ -24,6 +24,18 @@ public function testBootDefault() {
$this->assertRegExp('/^count is [0-9]+$/', $phpRun->getOutput());
}

public function testBootCmsFull() {
$phpBoot = Process::runOk($this->cv("php:boot --level=cms-full"));
$this->assertRegExp(';BEGINPHP;', $phpBoot->getOutput());
$this->assertRegExp(';ENDPHP;', $phpBoot->getOutput());

$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'printf("count is %s\n", CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_contact"));'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^count is [0-9]+$/', $phpRun->getOutput());
}

public function testBootClassLoader() {
$phpBoot = Process::runOk($this->cv("php:boot --level=classloader"));
$this->assertRegExp(';ClassLoader;', $phpBoot->getOutput());
Expand Down

0 comments on commit 248bc8a

Please sign in to comment.