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

[8.x] Account for a numerical array of views in Mailable::renderForAssertions() #35662

Merged
merged 1 commit into from
Dec 19, 2020
Merged

Conversation

paulredmond
Copy link
Contributor

This attempts to account for a numerical array returned from Mailable::buildView() within the new renderForAssertions() method introduced in afb858a. The update isn't elegant, but buildView can return a string so this checks if the $view is an array and if the numeric index is set.

I did not see any existing tests and realized it'd take more work to add template fixtures, container support, etc. to existing tests so please review carefully in case I missed something.

Steps to reproduce

// in a mailable
public function build()
{
    return $this->view('emails.my-email')
                ->text('emails.my-email-plain');
}

In the Mailable::renderForAssertions() method:

$html = Container::getInstance()->make('mailer')->render(
    $view = $this->buildView(), $this->buildViewData()
);

dd($view);
/*
array:2 [
  0 => "emails.my-email"
  1 => "emails.my-email-plain"
]
*/

The current logic (before this fix) works as expected when you use markdown or HTML in which Mailable::buildView() returns an associative array:

    return $this->html('Hello World')
                ->text('emails.my-email-plain');

/*
array:2 [
  "html" => Illuminate\Support\HtmlString^ {#114
    #html: "Hello World"
  }
  "text" => "emails.my-email-plain"
]
*/

Similar logic can be found in Mailer::parseView.

@paulredmond paulredmond changed the title Account for a numerical array of views Account for a numerical array of views in Mailable::renderForAssertions() Dec 18, 2020
@GrahamCampbell GrahamCampbell changed the title Account for a numerical array of views in Mailable::renderForAssertions() [8.x] Account for a numerical array of views in Mailable::renderForAssertions() Dec 18, 2020
@taylorotwell taylorotwell merged commit 990ae89 into laravel:8.x Dec 19, 2020
@paulredmond paulredmond deleted the patch-1 branch December 20, 2020 00:38
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