codeception-mailcatcher-module icon indicating copy to clipboard operation
codeception-mailcatcher-module copied to clipboard

more than just last email

Open dwenaus opened this issue 9 years ago • 12 comments

would be great to be able to find more than just the last email. I've got a process that sends two emails and I need to be able to check the second.

dwenaus avatar Dec 19 '14 17:12 dwenaus

Good idea. I don't really have time to work on this right now, but it should be pretty easy for somebody to implement:

  1. Add helper method: nthLastMessage(n)
  2. Make lastMessage() call this under the hood
  3. Add analogous ...inNthLastEmail... methods to match the existing ...inLastEmail... methods.
  4. Add documentation.

Pull request would be most welcome

captbaritone avatar Dec 19 '14 17:12 captbaritone

I wrote something like this, when I find some time I'll make a pull request. In the meantime feel free to use it from here https://gist.github.com/lollypopgr/591649190564fe57a4cd

drakakisgeo avatar Apr 09 '15 20:04 drakakisgeo

Looks good. I'll merge if you PR.

captbaritone avatar Apr 14 '15 02:04 captbaritone

Wow. This is fantastic! Do ya'll need help adding this to the repo?

dwenaus avatar May 27 '15 20:05 dwenaus

@dwenaus If you want to open a PR, I'd merge it.

captbaritone avatar May 27 '15 21:05 captbaritone

@dwenaus and @drakakisgeo is there still any interest in this, or should I close the issue?

captbaritone avatar Feb 09 '16 20:02 captbaritone

Yes, still interested :) On Tue, Feb 9, 2016 at 12:41 PM Jordan Eldredge [email protected] wrote:

@dwenaus https://github.com/dwenaus and @drakakisgeo https://github.com/drakakisgeo is there still any interest in this, or should I close the issue?

— Reply to this email directly or view it on GitHub https://github.com/captbaritone/codeception-mailcatcher-module/issues/12#issuecomment-182053939 .

dwenaus avatar Feb 10 '16 04:02 dwenaus

It's been only five years :) Is merging still possible?

stell avatar Aug 10 '21 10:08 stell

@stell Waiting for a PR in the repo...

Jamesking56 avatar Aug 10 '21 10:08 Jamesking56

I'm working on a PR, but I don't know how useful the tests are for this.

There's a non-functional method in the test right now (I guess that's the reason it's not active, aka has no test prefix): \Codeception\Util\MailCatcherTest::lastMessageFrom that would test something similar.

The problem lies with the Guzzle MockHandler in combination with \Codeception\Module\MailCatcher::emailFromId. I would have to specify exactly the response I expect for the handler anyway, so the test is pretty much worthless.

A test for seeInNthEmail would look something like this:

    public function testSeeInNthEmail()
    {
        $interestingMessage = [
            'id' => 2,
            'created_at' => date('c'),
            'sender' => '[email protected]',
            'recipients' => ['[email protected]'],
            'subject' => '',
        ];
        $handler = new MockHandler([
            new Response(200, [], json_encode([
                [
                    'id' => 1,
                    'created_at' => date('c'),
                    'sender' => '[email protected]',
                    'recipients' => ['[email protected]'],
                    'subject' => '',
                ],
                $interestingMessage
            ])),
            // \Codeception\Module\MailCatcher::emailFromId
            // $this->mailcatcher->get("/messages/{$id}.json");
            new Response(200, [], json_encode($interestingMessage)),
            // \Codeception\Module\MailCatcher::emailFromId
            // $plainMessage = $this->mailcatcher->get("/messages/{$id}.source");
            new Response(200, [], json_encode($interestingMessage))
        ]);
        $client = new Client(['handler' => $handler]);

        $mailcatcher = new MailCatcherTest_TestClass();
        $mailcatcher->setClient($client);

        $message = $mailcatcher->nthMessage(2);
        $this->assertEquals('2', $message->getId());
        $this->assertEquals(['[email protected]'], $message->getRecipients());
    }

The only thing that is tested here is if there are two items in the first response (if the right index in the nthMessage method is chosen).

Should I add such tests @Jamesking56?

wazum avatar Aug 26 '22 12:08 wazum

@wazum I think a weak test is better than no test at all, so yes I think still would be worth adding

Jamesking56 avatar Aug 29 '22 18:08 Jamesking56

Has anybody time to review my pull request? The feature has been requested for years and I finally implemented it. Would be nice to have it in a tagged version.

wazum avatar Sep 27 '22 07:09 wazum