Skip to content
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

Fix miscoordination between CiviUnitTestCase/CiviEnvBuilder. Fix flaky ConformanceTest. #25177

Merged
merged 4 commits into from
Dec 16, 2022
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
4 changes: 2 additions & 2 deletions Civi/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function pdo() {
*/
public static function headless() {
$civiRoot = dirname(__DIR__);
$builder = new \Civi\Test\CiviEnvBuilder('CiviEnvBuilder');
$builder = new \Civi\Test\CiviEnvBuilder();
$builder
->callback(function ($ctx) {
if (CIVICRM_UF !== 'UnitTests') {
Expand Down Expand Up @@ -139,7 +139,7 @@ public static function headless() {
* @return \Civi\Test\CiviEnvBuilder
*/
public static function e2e() {
$builder = new \Civi\Test\CiviEnvBuilder('CiviEnvBuilder');
$builder = new \Civi\Test\CiviEnvBuilder();
$builder
->callback(function ($ctx) {
if (CIVICRM_UF === 'UnitTests') {
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/CiviEnvBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CiviEnvBuilder {
*/
private $targetSignature = NULL;

public function __construct($name) {
public function __construct(string $name = 'CiviEnvBuilder') {
$this->name = $name;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ protected static function _populateDB($perClass = FALSE, &$object = NULL) {

Civi\Test::data()->populate();

// `CiviUnitTestCase` has replaced the baseline DB configuration. To coexist with other
// tests based on `CiviEnvBuilder`, we need to store a signature marking the current DB configuration.
(new \Civi\Test\CiviEnvBuilder())->callback(function(){}, 'CiviUnitTestCase')->apply(TRUE);

return TRUE;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/api/v4/Action/AutocompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public function on_civi_api_prepare(\Civi\API\Event\PrepareEvent $event) {
}
}

public function setUpHeadless() {
// TODO: search_kit should probably be part of the 'headless()' baseline.
return \Civi\Test::headless()->install(['org.civicrm.search_kit'])->apply();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work for getting 5.57 to a passing state. For master, we might move this to the parent (Api4TestBase::setUpHeadless()) or revise the definition of headless().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totten I'm moving this up to the parent in #25960

}

public function setUp(): void {
$this->hookCallback = NULL;
// Ensure MockBasicEntity gets added via above listener
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v4/Entity/ConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getEntitiesHitech(): array {
* @return array
*/
public function getEntitiesLotech(): array {
$manual['add'] = ['SearchDisplay', 'SearchSegment'];
$manual['add'] = [];
$manual['remove'] = ['CustomValue'];
$manual['transform'] = ['CiviCase' => 'Case'];

Expand Down