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

CRM-19690 - CiviMail - Add MailingSystemTest. Small code cleanups. #9564

Merged
merged 6 commits into from
Dec 23, 2016

Conversation

totten
Copy link
Member

@totten totten commented Dec 20, 2016

The main change here is to expand test-coverge of CiviMail's email
composition functionality via CRM_Mailing_MailingSystemTest and
CRM_Mailing_BaseMailingSystemTest. It improves coverage in some
areas which are conspicuously lacking coverage (e.g email tracking codes).

Additionally, this PR does some smaller cleanups to the BAO's -- for
details, check each commit separately.

Note: The new test is actually written as two classes, MailingSystemTest
and BaseMailingSystemTest. This is a bit unusual but serves a purpose
looking forward: under CRM-19690, we want to allow a replacement for
CiviMail's composition/delivery engine with a refactored version (aka
FlexMailer). The scenarios defined by BaseMailingSystemTest will be
shared by the two delivery engines to ensure that they behave the same way.


… `static`

This function is only called once, and it previously lacked test coverage,
so the `static` warning previously snuck through. Fix it!
…public

These two functions will be useful in FlexMailer's DefaultEngine.
@totten
Copy link
Member Author

totten commented Dec 20, 2016

The test failure CRM_Contact_BAO_ContactType_ContactTest.testCRM19133 is a common false-negative.

@totten
Copy link
Member Author

totten commented Dec 20, 2016

jenkins, test this please

@seamuslee001
Copy link
Contributor

Jenkins re test this please

Copy link
Member

@omarabuhussein omarabuhussein left a comment

Choose a reason for hiding this comment

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

left some notes

@@ -581,6 +530,7 @@ public function deliver(&$mailer, $testParams = NULL) {

// make sure that there's no more than $mailerBatchLimit mails processed in a run
$mailerBatchLimit = Civi::settings()->get('mailerBatchLimit');
$eq = self::findPendingTasks($this->id, $mailing->sms_provider_id ? 'sms' : 'email');
Copy link
Member

Choose a reason for hiding this comment

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

can you do this in a variable then pass it :

self::findPendingTasks( .... , $mailProvider );

it is more cleaner

* @return \CRM_Mailing_Event_BAO_Queue
* A query object whose rows provide ('id', 'contact_id', 'hash') and ('email' or 'phone').
*/
public static function findPendingTasks($jobId, $medium) {
Copy link
Member

Choose a reason for hiding this comment

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

this is an implementation details ... is their any benefits from making it public ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's actually the main purpose of the commit. FlexMailer will want to use the exact same query -- which can be accomplished by pulling the query into its own public function.

Copy link
Member

Choose a reason for hiding this comment

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

oh I see .. the commit message doesn't say about that nor the PR description so I wasn't sure about it

@@ -581,6 +530,7 @@ public function deliver(&$mailer, $testParams = NULL) {

// make sure that there's no more than $mailerBatchLimit mails processed in a run
$mailerBatchLimit = Civi::settings()->get('mailerBatchLimit');
$eq = self::findPendingTasks($this->id, $mailing->sms_provider_id ? 'sms' : 'email');
while ($eq->fetch()) {
// if ( ( $mailsProcessed % 100 ) == 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

not related to ur work , but can u please remove these commented out lines

/**
* @param int $jobId
* @param string $medium
* Ex: 'email' or 'sms'.
Copy link
Member

Choose a reason for hiding this comment

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

there should be a space between @param & @return .. also could you add a description for this method

$eq = new CRM_Mailing_Event_BAO_Queue();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$emailTable = CRM_Core_BAO_Email::getTableName();
$phoneTable = CRM_Core_DAO_Phone::getTableName();
Copy link
Member

Choose a reason for hiding this comment

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

I think this need to be consisitant .. CRM_Core_DAO_Phone should be changed to CRM_Core_BAO_Phone

* @see \Civi\FlexMailer\FlexMailerSystemTest
* @see CRM_Mailing_MailingSystemTest
*/
abstract class CRM_Mailing_BaseMailingSystemTest extends CiviUnitTestCase {
Copy link
Member

Choose a reason for hiding this comment

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

why this is an abstract class .. I see no need for that and also u don't have any abstract method in it

Copy link
Member

Choose a reason for hiding this comment

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

also same as in the other PR ... cannot use just use the headless interface for the tests

Copy link
Member

@omarabuhussein omarabuhussein Dec 22, 2016

Choose a reason for hiding this comment

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

forget about this comment above this one since we already discussed it

also same as in the other PR ... cannot use just use the headless interface for the tests

Copy link
Member Author

Choose a reason for hiding this comment

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

It's true that no function is specifically abstract, so syntactically there's no obligation to mark the class abstract.

However, semantically, the class is abstract. There will be two subclasses (MailingSystemTest and FlexMailerSystemTest) which extend BaseMailingSystemTest. BaseMailingSystemTest does not do everything needed for a test. It's abstract because

  • We don't want phpunit to execute BaseMailingSystemTest by itself. (It's not a complete test.)
  • Subclasses are expected to make some changes -- by overriding setUp().

Copy link
Member

@omarabuhussein omarabuhussein Dec 22, 2016

Choose a reason for hiding this comment

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

hmm , sorry... but tbh I am not really convinced with this reasoning ...

We don't want phpunit to execute BaseMailingSystemTest by itself. (It's not a complete test.)

so you are defining it as abstract as a kind of protection from execution these test methods in the abstract class .. but I am looking at this class again and I think that you might do not need to add the word test before the method names .. so in this case you don't need to define the class as abstract.

Subclasses are expected to make some changes -- by overriding setUp().

but overriding methods is something and abstract class is something else , right ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's try this question again:

why this is an abstract class .. I see no need for that and also u don't have any abstract method in it

From a design perspective, the answer is: because BaseMailingSystemTest should not be instantiated by itself. The content within the file BaseMailingSystemTest.php is a collection of general test scenarios which should be independent of particular implementations (e.g. current CiviMail vs FlexMailer). It would be meaningless to execute those general test scenarios unless you provide more details about the specific implementation to test.

so you are defining it as abstract as a kind of protection from execution these test methods in the abstract class .. but I am looking at this class again and I think that you might do not need to add the word test before the method names .. so in this case you don't need to define the class as abstract.

From a functional perspective, it is desirable behavior that phpunit does not try to execute the BaseMailingSystemTest content by itself. That behavior could be achieved in multiple ways, but I don't see a point exploring those hypotheticals when there's no specific problem with the current concrete solution. FWIW, putting abstract on the class seems both simple and semantically accurate to me.

@omarabuhussein
Copy link
Member

things looks fine now @totten

@totten totten merged commit 4e098b3 into civicrm:master Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants