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

Add email assertions trait #9322

Merged
merged 9 commits into from
Aug 30, 2016
Merged

Add email assertions trait #9322

merged 9 commits into from
Aug 30, 2016

Conversation

jadb
Copy link
Contributor

@jadb jadb commented Aug 21, 2016

This will allow assertions in tests, like:

$this->assertEmailTo('Tyler', 'tyler@evilcorp.com');
$this->assertEmailSubject('Tyler, welcome to Evil Corp');
$this->assertEmailTextMessageContains('Hey Tyler!');

I haven't written tests yet but will do once everyone thinks the API is good enough.

protected $_email;

/**
* @param array|string|null $content
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing parameter comment

@ADmad ADmad added this to the 3.3.2 milestone Aug 21, 2016

/**
* @param array|string|null $content The email's content to send.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing @return tag in function comment

* @param string $email Sender's email address.
* @param string $name Sender's name.
* @param string $message The failure message to define.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing @return tag in function comment

$expected = [$email => $name];
$result = $this->email()->to();
$this->assertSame($expected, $result, $message);
}
Copy link
Member

Choose a reason for hiding this comment

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

Should there also be assertions for cc, bcc and attachments?

Copy link
Contributor

Choose a reason for hiding this comment

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

and also maybe a assertEmailToContains() to look for an email address in a list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally, was just a PoC to start with.

@markstory
Copy link
Member

I think this is a neat idea. I like the trait approach more than another base class that requires inheritance.

@markstory markstory modified the milestones: 3.3.2, 3.3.3 Aug 22, 2016
}

/**
* @param string $expected Expected attachment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Doc comment for parameter $expected does not match actual variable name $filename

@jadb
Copy link
Contributor Author

jadb commented Aug 26, 2016

I have added all suggestions and written some functional tests which would serve as sample. Was not sure how to best unit test it without it just being mocks. Pointers welcomed.

@markstory
Copy link
Member

Functional tests are more valuable than a pile of mocks would be.

@jadb jadb changed the title [RFC] Add email assertions Add email assertions trait Aug 27, 2016
@codecov-io
Copy link

Current coverage is 95.12% (diff: 73.07%)

Merging #9322 into master will increase coverage by 0.12%

@@             master      #9322   diff @@
==========================================
  Files           410        411      +1   
  Lines         28055      29098   +1043   
  Methods        3362       3677    +315   
  Messages          0          0           
  Branches          0          0           
==========================================
+ Hits          26653      27680   +1027   
- Misses         1402       1418     +16   
  Partials          0          0           

Powered by Codecov. Last update daba072...22e150b


/**
* @param string $filename Expected attachment's filename.
* @param array $file Expected attachment's file info.
Copy link
Member

Choose a reason for hiding this comment

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

|null are missing in a few places.
You can use my sniffer to auto fix this by the way :)

@ravage84
Copy link
Member

@jadb Just curious. None of your test methods have a short description in the doc block.
I see your method names are quite self descriptive ( 👍 ), but is this way of doing accepted by our coding standard?

@jadb
Copy link
Contributor Author

jadb commented Aug 29, 2016

@ravage84 no. Just opted not to waste time before I make sure all is done and no methods needs changed or otherwise. But feel free to add descriptions and push to this PR if you want to help :)

*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.3.1
Copy link
Member

Choose a reason for hiding this comment

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

3.3.3 :)

@markstory markstory merged commit c3f45e8 into master Aug 30, 2016
@markstory markstory deleted the add-email-assertions branch August 30, 2016 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants