Skip to content

Conversation

JHWelch
Copy link
Contributor

@JHWelch JHWelch commented Jan 17, 2022

I'm adding assertSeeInOrderText and assertSeeInOrderHtml to the Mailable class to compliment the other test assertions already present. They work similarly to the assertSeeInOrder available on \Illuminate\Testing\TestResponse and use the same PHPUnit constraint.

This is useful for testing that your mail is displaying items in the order you would expect.

For instance for view

@component('mail::message')

# List
- Item 1
- Item 2
- Item 3

@endcomponent

and Mailable

class ListMail extends Mailable
{

public function build()
{
    return $this->markdown('mail.list');
}

You would be able to test if the list was in order with

/** @test */
public function list_items_are_in_order()
{
    $mailable = new ListMail;

    $mailable->assertSeeInOrderText([
        'Item 1',
        'Item 2',
        'Item 3',
    ]);
}

While trying to add tests for this assertion, I realized that none of the existing Mailable assertions were tested. I created MailMailableAssertionsTest to test the existing assertions and my new ones.

I found renderForAssertions pretty hard to mock out without a good example, so I just overrode it with the expected in the test. I thought this was at least better than no the current state of no tests. However, I could remove the tests from this PR if that is better, or spend some more time mocking it further from the tests if someone could point me in the right direction.

@JHWelch JHWelch changed the title [9.x] Add SeeInOrder mail assertions [9.x] Add SeeInOrder Mailable assertions Jan 17, 2022
@taylorotwell taylorotwell merged commit d08eaf6 into laravel:9.x Jan 17, 2022
@JHWelch JHWelch deleted the add-ordered-mail-assertions branch January 18, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants