codeception-mailcatcher-module
                                
                                 codeception-mailcatcher-module copied to clipboard
                                
                                    codeception-mailcatcher-module copied to clipboard
                            
                            
                            
                        more than just last email
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.
Good idea. I don't really have time to work on this right now, but it should be pretty easy for somebody to implement:
- Add helper method: nthLastMessage(n)
- Make lastMessage()call this under the hood
- Add analogous ...inNthLastEmail...methods to match the existing...inLastEmail...methods.
- Add documentation.
Pull request would be most welcome
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
Looks good. I'll merge if you PR.
Wow. This is fantastic! Do ya'll need help adding this to the repo?
@dwenaus If you want to open a PR, I'd merge it.
@dwenaus and @drakakisgeo is there still any interest in this, or should I close the issue?
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 .
It's been only five years :) Is merging still possible?
@stell Waiting for a PR in the repo...
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 I think a weak test is better than no test at all, so yes I think still would be worth adding
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.