Skip to content

Commit

Permalink
Merge pull request #31627 from totten/master-phpunit10-action
Browse files Browse the repository at this point in the history
PHPUnit 10 - Various fix for scheduled-reminder tests (et al)
  • Loading branch information
colemanw authored Dec 19, 2024
2 parents fe42faf + 02cd1de commit 649b4fb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 28 deletions.
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Activity/ActionMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
* NOTE: There are also pretty deep tests of activity-based reminders in
* CRM_Core_BAO_ActionScheduleTest.
*
* @see \Civi\ActionSchedule\AbstractMappingTest
* @see \Civi\ActionSchedule\AbstractMappingTestCase
* @see CRM_Core_BAO_ActionScheduleTest
*/
class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappingTest {
class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappingTestCase {

/**
* Generate a list of test cases, where each is a distinct combination of
Expand All @@ -40,7 +40,7 @@ class CRM_Activity_ActionMappingTest extends \Civi\ActionSchedule\AbstractMappin
* - recipients: array of emails
* - subject: regex
*/
public function createTestCases() {
public static function createTestCases(): array {
$cs = [];

$cs[] = [
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
+--------------------------------------------------------------------+
*/

use Civi\ActionSchedule\AbstractMappingTest;
use Civi\ActionSchedule\AbstractMappingTestCase;
use Civi\Api4\Contribution;
use Civi\Token\TokenProcessor;

Expand All @@ -21,10 +21,10 @@
* reminders for *contribution types*. It follows a design/pattern described in
* AbstractMappingTest.
*
* @see \Civi\ActionSchedule\AbstractMappingTest
* @see \Civi\ActionSchedule\AbstractMappingTestCase
* @group headless
*/
class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTest {
class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTestCase {

/**
* Generate a list of test cases, where each is a distinct combination of
Expand All @@ -39,7 +39,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends AbstractMappingTest {
* - recipients: array of emails
* - subject: regex
*/
public function createTestCases(): array {
public static function createTestCases(): array {
$cs = [];

$cs[] = [
Expand Down Expand Up @@ -193,7 +193,7 @@ public function createTestCases(): array {
* Create a contribution record for Alice with type "Member Dues".
*/
public function addAliceDues(): void {
$campaignID = $this->campaignCreate([
$campaignID = $this->ids['Campaign']['big'] = $this->campaignCreate([
'title' => 'Campaign',
'name' => 'big_campaign',
]);
Expand Down Expand Up @@ -373,7 +373,7 @@ public function testTokenRendering(): void {
'fee_amount = €5.00',
'paid_amount = €100.00',
'balance_amount = €0.00',
'campaign_id = 1',
'campaign_id = ' . $this->ids['Campaign']['big'],
'campaign name = big_campaign',
'campaign label = Campaign',
'receipt text = Thank you!',
Expand Down
51 changes: 41 additions & 10 deletions tests/phpunit/CRM/Event/ActionMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
+--------------------------------------------------------------------+
*/

use Civi\ActionSchedule\AbstractMappingTest;
use Civi\ActionSchedule\AbstractMappingTestCase;

/**
* Class CRM_Event_ActionMappingTest
Expand All @@ -18,25 +18,56 @@
* This class tests various configurations of event scheduled-reminders. It follows a design/pattern described in
* AbstractMappingTest.
*
* @see \Civi\ActionSchedule\AbstractMappingTest
* @see \Civi\ActionSchedule\AbstractMappingTestCase
* @group headless
*/
class CRM_Event_ActionMappingTest extends AbstractMappingTest {
class CRM_Event_ActionMappingTest extends AbstractMappingTestCase {

public function createTestCases() {
public static function createTestCases(): array {
$cs = [];

$cs[] = [
'2015-02-01 00:00:00',
'createReunion registerAliceDualRole scheduleForEventStart startWeekBefore targetByRole useHelloFirstName',
[
[
'time' => '2015-01-25 00:00:00',
'to' => ['[email protected]'],
'subject' => '/Hello, Alice/',
],
],
];

return $cs;
}

public function createReunion(array $params = [], string $identifier = 'event') {
$this->eventCreateUnpaid([
'title' => 'Roadie Reunion',
'start_date' => '2015-02-01 00:00:00',
'end_date' => '2015-02-03 05:00:00',
'registration_start_date' => '2014-08-01 09:00:00',
'registration_end_date' => '2015-01-15 23:59:59',
]);
}

public function testLimitByRoleID(): void {
$this->participantCreate(['role_id' => [1, 2], 'event_id' => $this->eventCreateUnpaid()['id']]);
public function registerAliceDualRole() {
$this->participantCreate([
'role_id' => [1, 2],
'contact_id' => $this->contacts['alice']['id'],
'event_id' => $this->getEventID(),
]);
}

public function scheduleForEventStart(): void {
$this->schedule->mapping_id = CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID;
$this->schedule->start_action_date = 'start_date';
$this->schedule->entity_value = $this->getEventID();
}

public function targetByRole(): void {
$this->schedule->limit_to = 1;
$this->schedule->recipient_listing = 1;
$this->startWeekBefore();
$this->useHelloFirstName();
$this->schedule->save();
$this->callAPISuccess('Job', 'send_reminder', []);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @see CRM_Contribute_ActionMapping_ByTypeTest
* @see CRM_Activity_ActionMappingTest
*/
abstract class AbstractMappingTest extends \CiviUnitTestCase {
abstract class AbstractMappingTestCase extends \CiviUnitTestCase {

/**
* @var \CRM_Core_DAO_ActionSchedule
Expand Down Expand Up @@ -95,7 +95,7 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase {
* - subject: regex
* - message: regex
*/
abstract public function createTestCases();
abstract public static function createTestCases(): array;

// ---------------------------------------- Setup Helpers ----------------------------------------

Expand Down Expand Up @@ -198,7 +198,7 @@ protected function setUp(): void {
];

$this->schedule = new \CRM_Core_DAO_ActionSchedule();
$this->schedule->title = $this->getName(TRUE);
$this->schedule->title = is_callable([$this, 'name']) ? $this->name() : $this->getName(TRUE);
$this->schedule->name = \CRM_Utils_String::munge($this->schedule->title);
$this->schedule->is_active = 1;
$this->schedule->group_id = NULL;
Expand Down Expand Up @@ -274,6 +274,9 @@ protected function setUp(): void {
* @throws \Exception
*/
public function testDefault(string $targetDate, string $setupFuncs, array $expectMessages) {
if ($targetDate === 'INCOMPLETE') {
$this->markTestIncomplete();
}
$this->targetDate = $targetDate;

foreach (explode(' ', $setupFuncs) as $setupFunc) {
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/Civi/ActionSchedule/SavedSearchMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* Test scheduled-communications based on SavedSearches.
*
* @group ActionSchedule
* @see \Civi\ActionSchedule\AbstractMappingTest
* @see \Civi\ActionSchedule\AbstractMappingTestCase
* @group headless
*/
class SavedSearchMappingTest extends AbstractMappingTest {
class SavedSearchMappingTest extends AbstractMappingTestCase {

protected $savedSearch = [];

Expand Down Expand Up @@ -159,8 +159,8 @@ protected function setDateField(string $fieldName): void {
/**
* Disable testDefault by returning no test cases
*/
public function createTestCases() {
return [];
public static function createTestCases(): array {
return [['INCOMPLETE', '', []]];
}

}
3 changes: 1 addition & 2 deletions tests/phpunit/api/v4/Custom/CustomFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

namespace Civi\tests\phpunit\api\v4\Custom;
namespace api\v4\Custom;

use api\v4\Custom\CustomTestBase;
use Civi\Api4\CustomGroup;
use Civi\Api4\CustomField;
use Civi\Api4\File;
Expand Down

0 comments on commit 649b4fb

Please sign in to comment.