-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
… `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.
The test failure |
jenkins, test this please |
Jenkins re test this please |
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 executeBaseMailingSystemTest
by itself. (It's not a complete test.) - Subclasses are expected to make some changes -- by overriding
setUp()
.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
things looks fine now @totten |
The main change here is to expand test-coverge of CiviMail's email
composition functionality via
CRM_Mailing_MailingSystemTest
andCRM_Mailing_BaseMailingSystemTest
. It improves coverage in someareas 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 purposelooking 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 byBaseMailingSystemTest
will beshared by the two delivery engines to ensure that they behave the same way.