8000 PHPUnit - Update 8.x => 9.x by totten · Pull Request #196 · civicrm/cv · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PHPUnit - Update 8.x => 9.x #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<phpunit backupGlobals="false"
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
Expand All @@ -8,16 +10,15 @@
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
cacheResult="false"
>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Cv Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
8 changes: 4 additions & 4 deletions tests/Command/AngularHtmlListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ class AngularHtmlListCommandTest extends \Civi\Cv\CivilTestCase {
*/
public function testGetRegex() {
$p = Process::runOk($this->cv('ang:html:list'));
$this->assertRegexp(';crmUi/field.html;', $p->getOutput());
$this->assertMatchesRegularExpression(';crmUi/field.html;', $p->getOutput());

// matches key
$p = Process::runOk($this->cv('ang:html:list crmUi'));
$this->assertRegexp(';crmUi/field.html;', $p->getOutput());
$this->assertMatchesRegularExpression(';crmUi/field.html;', $p->getOutput());

// matches name
$p = Process::runOk($this->cv('ang:html:list ";field;"'));
$this->assertRegexp(';crmUi/field.html;', $p->getOutput());
$this->assertMatchesRegularExpression(';crmUi/field.html;', $p->getOutput());

// matches name
$p = Process::runOk($this->cv('ang:html:list crmAttachment'));
$this->assertNotRegexp(';crmUi/field.html;', $p->getOutput());
$this->assertDoesNotMatchRegularExpression(';crmUi/field.html;', $p->getOutput());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Command/AngularHtmlShowCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public function setUp(): void {
public function testShow() {

$p = Process::runOk($this->cv('ang:html:show crmUi/field.html'));
$this->assertRegexp(';div.*ng-transclude;', $p->getOutput());
$this->assertMatchesRegularExpression(';div.*ng-transclude;', $p->getOutput());
}

/**
* List extensions using a regular expression.
*/
public function testShowRaw() {
$p = Process::runOk($this->cv('ang:html:show --raw crmUi/field.html'));
$this->assertRegexp(';div.*ng-transclude;', $p->getOutput());
$this->assertMatchesRegularExpression(';div.*ng-transclude;', $p->getOutput());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/AngularModuleListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class AngularModuleListCommandTest extends \Civi\Cv\CivilTestCase {
*/
public function testGetRegex() {
$p = Process::runOk($this->cv('ang:module:list'));
$this->assertRegexp(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());
$this->assertMatchesRegularExpression(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());

$p = Process::runOk($this->cv('ang:module:list ";crm;"'));
$this->assertRegexp(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());
$this->assertMatchesRegularExpression(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());

$p = Process::runOk($this->cv('ang:module:list ";foo;"'));
$this->assertNotRegexp(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());
$this->assertDoesNotMatchRegularExpression(';crmUi.*civicrm/a.*crmResource;', $p->getOutput());
}

}
2 changes: 1 addition & 1 deletion tests/Command/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testCsv() {

public function testCsvMisuse() {
$p = Process::runOk($this->cv("api OptionValue.getsingle rowCount=1 --out=csv"));
$this->assertRegExp('/The output format "csv" only works with tabular data. Try using a "get" API. Forcing format to "json-pretty"./', $p->getErrorOutput());
$this->assertMatchesRegularExpression('/The output format "csv" only works with tabular data. Try using a "get" API. Forcing format to "json-pretty"./', $p->getErrorOutput());
$data = json_decode($p->getOutput(), 1);
$this->assertTrue(!empty($data['option_group_id']));
}
Expand Down
22 changes: 11 additions & 11 deletions tests/Command/BootCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,53 @@ public function setUp(): void {

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

$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'printf("count is %s\n", CRM_Core_DAO::singleValueQuery("select count(*) from civicrm_contact"));'
. 'printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^count is [0-9]+\n/', $phpRun->getOutput());
$this->assertRegExp('/my admin is \w+\n/', $phpRun->getOutput());
$this->assertMatchesRegularExpression('/^count is [0-9]+\n/', $phpRun->getOutput());
$this->assertMatchesRegularExpression('/my admin is \w+\n/', $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());
$this->assertMatchesRegularExpression(';BEGINPHP;', $phpBoot->getOutput());
$this->assertMatchesRegularExpression(';ENDPHP;', $phpBoot->getOutput());

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

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

// In the classloader level, config vals like CIVICRM_DSN are not loaded.
$helloPhp = escapeshellarg($phpBoot->getOutput()
. '$x=array("a"=>defined("CIVICRM_DSN") ? "yup" : "nope");'
. 'printf("phpr says %s\n", CRM_Utils_Array::value("a",$x));'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -r $helloPhp"));
$this->assertRegExp('/^phpr says nope$/', $phpRun->getOutput());
$this->assertMatchesRegularExpression('/^phpr says nope$/', $phpRun->getOutput());
}

public function testBootTest() {
$phpBoot = Process::runOk($this->cv("php:boot --test"));
$this->assertRegExp(';CIVICRM_SETTINGS_PATH;', $phpBoot->getOutput());
$this->assertMatchesRegularExpression(';CIVICRM_SETTINGS_PATH;', $phpBoot->getOutput());

$helloPhp = escapeshellarg($phpBoot->getOutput()
. 'echo CIVICRM_UF;'
);
$phpRun = Process::runOk(new \Symfony\Component\Process\Process("php -ddisplay_errors=1 -r $helloPhp"));
$this->assertRegExp('/UnitTests/i', $phpRun->getOutput());
$this->assertMatchesRegularExpression('/UnitTests/i', $phpRun->getOutput());
}

}
30 changes: 15 additions & 15 deletions tests/Command/CoreLifecycleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,41 +94,41 @@ public function testStandardLifecycle($buildType, $downloads, $installCmd, $post

// We've installed CMS -- but not Civi. Expect an error.
$output = $this->cvFail("ev 'return CRM_Utils_System::version();'");
$this->assertRegExp('/Failed to locate civicrm.settings.php/', $output);
$this->assertMatchesRegularExpression('/Failed to locate civicrm.settings.php/', $output);

$output = Process::runDebug($this->cv('core:check-req --out=table'))->getOutput();
$this->assertRegExp('/Found.*civicrm-core/', $output);
$this->assertRegExp('/Found.*civicrm-setup/', $output);
$this->assertRegExp('/| *info *| *lang/', $output);
$this->assertMatchesRegularExpression('/Found.*civicrm-core/', $output);
$this->assertMatchesRegularExpression('/Found.*civicrm-setup/', $output);
$this->assertMatchesRegularExpression('/| *info *| *lang/', $output);

$output = $this->cvOk($installCmd);
$this->assertRegExp('/Creating file.*civicrm.settings.php/', $output);
$this->assertRegExp('/Creating civicrm_\* database/', $output);
$this->assertMatchesRegularExpression('/Creating file.*civicrm.settings.php/', $output);
$this->assertMatchesRegularExpression('/Creating civicrm_\* database/', $output);

if ($postInstallCmd) {
Process::runOk(new \Symfony\Component\Process\Process($postInstallCmd));
}

// We've installed CMS+Civi. All should be well.
$result = $this->cvJsonOk("ev 'return CRM_Utils_System::version();'");
$this->assertRegExp('/^[0-9]([0-9\.]|alpha|beta)+$/', $result);
$this->assertMatchesRegularExpression('/^[0-9]([0-9\.]|alpha|beta)+$/', $result);
$this->assertTrue(version_compare($result, '4.6.0', '>='));

// The upgrade command doesn't have much to do, but let's make sure it doesn't crash.
$output = $this->cvOk("upgrade:db");
$this->assertRegExp('/Found CiviCRM database version ([0-9\.]|alpha|beta)+/', $output);
$this->assertRegExp('/Found CiviCRM code version ([0-9\.]|alpha|beta)+/', $output);
$this->assertRegExp('/\[latestVer\] => ([0-9\.]|alpha|beta)+/', $output);
$this->assertRegExp('/\[message\] => You are already/', $output);
$this->assertRegExp('/\[text\] => You are already/', $output);
$this->assertMatchesRegularExpression('/Found CiviCRM database version ([0-9\.]|alpha|beta)+/', $output);
$this->assertMatchesRegularExpression('/Found CiviCRM code version ([0-9\.]|alpha|beta)+/', $output);
$this->assertMatchesRegularExpression('/\[latestVer\] => ([0-9\.]|alpha|beta)+/', $output);
$this->assertMatchesRegularExpression('/\[message\] => You are already/', $output);
$this->assertMatchesRegularExpression('/\[text\] => You are already/', $output);

$output = $this->cvOk('core:uninstall -f');
$this->assertRegExp('/Removing .*civicrm.settings.php/', $output);
$this->assertRegExp('/Removing civicrm_\*/', $output);
$this->assertMatchesRegularExpression('/Removing .*civicrm.settings.php/', $output);
$this->assertMatchesRegularExpression('/Removing civicrm_\*/', $output);

// We've n o longer got Civi - expect an error.
$output = $this->cvFail("ev 'return CRM_Utils_System::version();'");
$this->assertRegExp('/Failed to locate civicrm.settings.php/', $output);
$this->assertMatchesRegularExpression('/Failed to locate civicrm.settings.php/', $output);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/Command/DebugContainerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public function setUp(): void {

public function testShowAll() {
$p = Process::runOk($this->cv("debug:container"));
$this->assertRegExp('/cxn_reg_client.*Civi.Cxn.Rpc.RegistrationClient/', $p->getOutput());
$this->assertRegExp('/civi_api_kernel.*Civi.API.Kernel/', $p->getOutput());
$this->assertMatchesRegularExpression('/cxn_reg_client.*Civi.Cxn.Rpc.RegistrationClient/', $p->getOutput());
$this->assertMatchesRegularExpression('/civi_api_kernel.*Civi.API.Kernel/', $p->getOutput());
}

// public function testName() {
// $p = Process::runOk($this->cv("debug:container hook_civicrm_caseChange"));
// $this->assertRegExp('/hook_civicrm_caseChange/', $p->getOutput());
// $this->assertNotRegExp('/hook_civicrm_post/', $p->getOutput());
// $this->assertNotRegExp('/civi.token.eval/', $p->getOutput());
// $this->assertMatchesRegularExpression('/hook_civicrm_caseChange/', $p->getOutput());
// $this->assertDoesNotMatchRegularExpression('/hook_civicrm_post/', $p->getOutput());
// $this->assertDoesNotMatchRegularExpression('/civi.token.eval/', $p->getOutput());
// }

// public function testRegExp() {
// $p = Process::runOk($this->cv("debug:container /^hook/"));
// $this->assertRegExp('/hook_civicrm_caseChange/', $p->getOutput());
// $this->assertRegExp('/hook_civicrm_post/', $p->getOutput());
// $this->assertNotRegExp('/civi.token.eval/', $p->getOutput());
// $this->assertMatchesRegularExpression('/hook_civicrm_caseChange/', $p->getOutput());
// $this->assertMatchesRegularExpression('/hook_civicrm_post/', $p->getOutput());
// $this->assertDoesNotMatchRegularExpression('/civi.token.eval/', $p->getOutput());
// }

}
18 changes: 9 additions & 9 deletions tests/Command/DebugDispatcherCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ public function setUp(): void {

public function testNoArg() {
$p = Process::runOk($this->cv("debug:event-dispatcher"));
$this->assertRegExp('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertRegExp('/hook_civicrm_post/', $p->getOutput());
$this->assertRegExp('/civi.token.eval/', $p->getOutput());
$this->assertMatchesRegularExpression('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertMatchesRegularExpression('/hook_civicrm_post/', $p->getOutput());
$this->assertMatchesRegularExpression('/civi.token.eval/', $p->getOutput());
}

public function testName() {
$p = Process::runOk($this->cv("debug:event-dispatcher hook_civicrm_caseChange"));
$this->assertRegExp('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertNotRegExp('/hook_civicrm_post/', $p->getOutput());
$this->assertNotRegExp('/civi.token.eval/', $p->getOutput());
$this->assertMatchesRegularExpression('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertDoesNotMatchRegularExpression('/hook_civicrm_post/', $p->getOutput());
$this->assertDoesNotMatchRegularExpression('/civi.token.eval/', $p->getOutput());
}

public function testRegExp() {
$p = Process::runOk($this->cv("debug:event-dispatcher /^hook/"));
$this->assertRegExp('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertRegExp('/hook_civicrm_post/', $p->getOutput());
$this->assertNotRegExp('/civi.token.eval/', $p->getOutput());
$this->assertMatchesRegularExpression('/hook_civicrm_caseChange/', $p->getOutput());
$this->assertMatchesRegularExpression('/hook_civicrm_post/', $p->getOutput());
$this->assertDoesNotMatchRegularExpression('/civi.token.eval/', $p->getOutput());
}

}
22 changes: 11 additions & 11 deletions tests/Command/EvalCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function setUp(): void {
public function testEv() {
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
$this->assertMatchesRegularExpression('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}

public function testPhpEval_ReturnObj_json() {
$phpCode = escapeshellarg('return (object)["ab"=>"cd"];');
$p = Process::runOk($this->cv("ev $phpCode --out=json"));
$this->assertEquals(0, $p->getExitCode());
$this->assertRegExp(';"ab":\w*"cd\";', $p->getOutput());
$this->assertMatchesRegularExpression(';"ab":\w*"cd\";', $p->getOutput());
}

public function testPhpEval_ReturnObj_shell() {
Expand All @@ -36,14 +36,14 @@ public function testPhpEval_ReturnObj_shell() {
$escaped = escapeshellarg($phpCode);
$p = Process::runOk($this->cv("ev $escaped --out=shell"));
$this->assertEquals(0, $p->getExitCode());
$this->assertRegExp(';ab=["\']cd;', $p->getOutput());
$this->assertMatchesRegularExpression(';ab=["\']cd;', $p->getOutput());
}
}

public function testPhpEval() {
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
$this->assertMatchesRegularExpression('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}

public function testPhpEval_Exit0() {
Expand All @@ -64,20 +64,20 @@ public function testPhpEval_ExitCodeError() {
public function testPhpEval_CvVar_Full() {
$helloPhp = escapeshellarg('printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);');
$p = Process::runOk($this->cv("ev --level=full $helloPhp"));
$this->assertRegExp('/^my admin is \w+\s*$/', $p->getOutput());
$this->assertMatchesRegularExpression('/^my admin is \w+\s*$/', $p->getOutput());
}

public function testPhpEval_CvVar_CmsFull() {
$helloPhp = escapeshellarg('printf("my admin is %s\n", $GLOBALS["_CV"]["ADMIN_USER"]);');
$p = Process::runOk($this->cv("ev --level=cms-full $helloPhp"));
$this->assertRegExp('/^my admin is \w+\s*$/', $p->getOutput());
$this->assertMatchesRegularExpression('/^my admin is \w+\s*$/', $p->getOutput());
}

public function testBoot() {
$checkBoot = escapeshellarg('echo (function_exists("drupal_add_js") || function_exists("wp_redirect") || class_exists("JFactory") || class_exists("Drupal")) ? "found" : "not-found";');

$p1 = Process::runOk($this->cv("ev $checkBoot"));
$this->assertRegExp('/^found$/', $p1->getOutput());
$this->assertMatchesRegularExpression('/^found$/', $p1->getOutput());
}

public function getLevels() {
Expand All @@ -98,17 +98,17 @@ public function testBootLevels($level) {
$checkBoot = escapeshellarg('echo "Hello world";');

$p1 = Process::runOk($this->cv("ev $checkBoot --level=$level"));
$this->assertRegExp('/^Hello world/', $p1->getOutput());
$this->assertMatchesRegularExpression('/^Hello world/', $p1->getOutput());
}

public function testTestMode() {
$checkUf = escapeshellarg('return CIVICRM_UF;');

$p1 = Process::runOk($this->cv("ev $checkUf"));
$this->assertRegExp('/(Drupal|Joomla|WordPress|Backdrop)/i', $p1->getOutput());
$this->assertMatchesRegularExpression('/(Drupal|Joomla|WordPress|Backdrop)/i', $p1->getOutput());

$p1 = Process::runOk($this->cv("ev -t $checkUf"));
$this->assertRegExp('/UnitTests/i', $p1->getOutput());
$this->assertMatchesRegularExpression('/UnitTests/i', $p1->getOutput());
}

/**
Expand All @@ -120,7 +120,7 @@ public function testEvalWithCwdOption() {
$cwdOpt = "--cwd=" . escapeshellarg($this->getExampleDir());
$helloPhp = escapeshellarg('printf("eval says version is %s\n", CRM_Utils_System::version());');
$p = Process::runOk($this->cv("ev $cwdOpt $helloPhp"));
$this->assertRegExp('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
$this->assertMatchesRegularExpression('/^eval says version is [0-9a-z\.]+\s*$/', $p->getOutput());
}

}
2 changes: 1 addition & 1 deletion tests/Command/ExtensionLifecycleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testDownloadWithExplicitUrl() {
*/
public function testUpgradeDb() {
$p = Process::runOk($this->cv('ext:upgrade-db'));
$this->assertRegExp(';Applying database upgrades from extensions;', $p->getOutput());
$this->assertMatchesRegularExpression(';Applying database upgrades from extensions;', $p->getOutput());
}

/**
Expand Down
Loading
0