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

Fixes unstable email integration tests #27892

Merged

Conversation

hostep
Copy link
Contributor

@hostep hostep commented Apr 18, 2020

Description (*)

This is re-adding the fixes added in #25296

Following changes made the email integration tests unstable again:

Related Pull Requests

Should fix integration tests which now fail in #27888

Fixed Issues (if relevant)

  • None

Manual testing scenarios (*)

See #25296

Questions or comments

Can we do something to avoid Magento core devs for re-introducing this incorrect way of testing email content?

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

…which had a maximum line length of 76 to a parseable string without a maximum line length, so there is no chance a particular string used in an assertion is getting splitted over multiple lines - Part 2.
@m2-assistant
Copy link

m2-assistant bot commented Apr 18, 2020

Hi @hostep. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@lbajsarowicz
Copy link
Contributor

lbajsarowicz commented Apr 18, 2020

I've addressed that in: #27606

private function assertSameGreeting(string $expectedGreeting, EmailMessage $message)
{
$messageContent = $this->getMessageRawContent($message);
$emailDom = new \DOMDocument();
$emailDom->loadHTML($messageContent);
$emailXpath = new \DOMXPath($emailDom);
$greeting = $emailXpath->query('//p[@class="greeting"]');
$this->assertSame(1, $greeting->length);
$this->assertSame($expectedGreeting, $greeting->item(0)->textContent);
}

Using DOM structure instead of assertContains (which is deprecated, btw).

There's also ticket to introduce DOM assertions:
#27607

@hostep
Copy link
Contributor Author

hostep commented Apr 19, 2020

Aha, thanks for the info @lbajsarowicz!

Let me try to update this PR to use the same DOM assertions then.
That will then also settle ticket #27607 I assume?

@hostep hostep force-pushed the fix-unstable-email-tests-part2 branch from 3ec905f to 69fcf67 Compare April 19, 2020 09:06
@hostep
Copy link
Contributor Author

hostep commented Apr 19, 2020

@lbajsarowicz: updated PR (rebased on latest 2.4-develop branch, amended commit and force pushed)

Before we fix all the occurrences (I count about 16 more classes using the getRawContent method), here are a couple of questions first:

  • Can you explain the deprecation of the assertContains method a bit, I can't seem to find information about that, what should it be replaced with?
  • I've written a generic assertEmailContains method, which can probably be re-used in all classes. Is that one ok? Where can we put this method so we don't need to copy it in all the test files?

Thanks!

@hostep hostep changed the title Fixes unstable email integration tests, by decoding the raw contents … Fixes unstable email integration tests, by asserting the content using DomNodes Apr 19, 2020
@lbajsarowicz
Copy link
Contributor

@hostep assertContains won't work with string anymore

https://phpunit.readthedocs.io/en/9.0/assertions.html

It's replacement is assertStringContainsString

@hostep
Copy link
Contributor Author

hostep commented Apr 19, 2020

I came by that article indeed, and tested assertStringContainsString, but assertStringContainsString doesn't exists yet in PHPUnit 6.5 which Magento is using ...
I've seen you working on PHPUnit 8 compatibility, but that's not finished yet I think?

@lbajsarowicz
Copy link
Contributor

Could you change this to assertStringContainsString? We will add your change once the PHPUnit 8 is finally introduced (team of people are working on this right now)

@hostep
Copy link
Contributor Author

hostep commented Apr 19, 2020

Hmm, I'd rather solve this as fast as possible, because the unstable email integration tests cause failures in this very good PR: #27888

If you want me to revert back to my old changes or keep this half-finished work and merge that first. And later handle a better way of handling it, that's also fine by me.

@lbajsarowicz
Copy link
Contributor

Yeah, so choose the MVP, and later on we'll do it the right way : )

@hostep hostep force-pushed the fix-unstable-email-tests-part2 branch from 69fcf67 to 3ec905f Compare April 19, 2020 18:26
@hostep hostep changed the title Fixes unstable email integration tests, by asserting the content using DomNodes Fixes unstable email integration tests Apr 19, 2020
@hostep
Copy link
Contributor Author

hostep commented Apr 19, 2020

Ok, I've reverted to my initial changes.

I've pushed my other changes to a different branch, just in case if somebody wants to get some inspiration from them: hostep/magento2@c163118...first-part-to-fix-issue-27607 when trying to fix #27607

@ghost ghost assigned ihor-sviziev Apr 22, 2020
@ihor-sviziev ihor-sviziev added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix labels Apr 22, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7467 has been created to process this Pull Request

@engcom-Alfa engcom-Alfa self-assigned this Apr 23, 2020
@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@m2-assistant
Copy link

m2-assistant bot commented Apr 25, 2020

Hi @hostep, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants