Skip to content

Commit

Permalink
Add tests for the setAdditionalData method (#66)
Browse files Browse the repository at this point in the history
* Add tests for the setAdditionalData method



---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/spatie/laravel-database-mail-templates?shareId=XXXX-XXXX-XXXX-XXXX).

* Fix styling

---------

Co-authored-by: AlexVanderbist <[email protected]>
  • Loading branch information
AlexVanderbist and AlexVanderbist authored Oct 3, 2024
1 parent c8c469a commit 093eba4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"php":"8.3.12","version":"3.64.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","do","else","elseif","final","for","foreach","function","if","interface","namespace","private","protected","public","static","switch","trait","try","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"single_trait_insert_per_statement":true},"hashes":{"src\/TemplateMailableRenderer.php":"66b692e33b4e16c4548edc284e443435","src\/Interfaces\/MailTemplateInterface.php":"0464eba1478bf93771af45c1c692e3d5","src\/TemplateMailable.php":"4c3ab61bba1e2786baed2fe19dcd1175","src\/Exceptions\/CannotRenderTemplateMailable.php":"eb7655921d96d6f214c378c156f8f82a","src\/Exceptions\/MissingMailTemplate.php":"4f27bdaf5578f1c49e47ecda64ae598c","src\/MailTemplatesServiceProvider.php":"6299fc9b66e1fc89ce693da634ef3cc0","src\/Models\/MailTemplate.php":"14264d26adf35b27748b7f78ded608cd","tests\/CustomMailTemplateTest.php":"b4ccad5f1306b28cbd3d328e89745407","tests\/stubs\/Mails\/BadLayoutMail.php":"1f8b60df779164992e526c7f664e6aed","tests\/stubs\/Mails\/CustomTemplateModelMail.php":"970174e4d825aeca75c25b4b61e285d6","tests\/stubs\/Mails\/LayoutMail.php":"52f4049e46db4e1b7103b24a7d30b66d","tests\/stubs\/Mails\/BasicMail.php":"40326d47d594a648280b504ee2a11b6a","tests\/stubs\/Models\/LayoutMailTemplate.php":"96581b0dbe44523a61e4ef3c25963cb8","tests\/stubs\/Models\/CustomMailTemplate.php":"d093379f9df235eb8f62ecf528ae872f","tests\/MailTemplateModelTest.php":"47fd136a71eb4f3b7cdf7c04850b2349","tests\/TemplateMailableTest.php":"056299e6a6c6fdfd1e6eda460b4d10ce","tests\/TestCase.php":"8e0f089954a47b21367902fb5cb9caa7"}}
{"php":"8.3.12","version":"3.64.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","do","else","elseif","final","for","foreach","function","if","interface","namespace","private","protected","public","static","switch","trait","try","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"single_trait_insert_per_statement":true},"hashes":{"src\/TemplateMailableRenderer.php":"66b692e33b4e16c4548edc284e443435","src\/Interfaces\/MailTemplateInterface.php":"0464eba1478bf93771af45c1c692e3d5","src\/TemplateMailable.php":"4c3ab61bba1e2786baed2fe19dcd1175","src\/Exceptions\/CannotRenderTemplateMailable.php":"eb7655921d96d6f214c378c156f8f82a","src\/Exceptions\/MissingMailTemplate.php":"4f27bdaf5578f1c49e47ecda64ae598c","src\/MailTemplatesServiceProvider.php":"6299fc9b66e1fc89ce693da634ef3cc0","src\/Models\/MailTemplate.php":"14264d26adf35b27748b7f78ded608cd","tests\/CustomMailTemplateTest.php":"b4ccad5f1306b28cbd3d328e89745407","tests\/stubs\/Mails\/BadLayoutMail.php":"1f8b60df779164992e526c7f664e6aed","tests\/stubs\/Mails\/CustomTemplateModelMail.php":"970174e4d825aeca75c25b4b61e285d6","tests\/stubs\/Mails\/LayoutMail.php":"52f4049e46db4e1b7103b24a7d30b66d","tests\/stubs\/Mails\/BasicMail.php":"40326d47d594a648280b504ee2a11b6a","tests\/stubs\/Models\/LayoutMailTemplate.php":"96581b0dbe44523a61e4ef3c25963cb8","tests\/stubs\/Models\/CustomMailTemplate.php":"d093379f9df235eb8f62ecf528ae872f","tests\/MailTemplateModelTest.php":"47fd136a71eb4f3b7cdf7c04850b2349","tests\/TemplateMailableTest.php":"d3c6de0d4b7b169c953efd448c3b73e1","tests\/TestCase.php":"8e0f089954a47b21367902fb5cb9caa7"}}
16 changes: 16 additions & 0 deletions tests/TemplateMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ public function it_throws_an_exception_if_no_mail_template_exists_for_mailable()

(new BasicMail('John'))->render();
}

/** @test */
public function it_can_set_additional_data()
{
MailTemplate::create([
'mailable' => BasicMail::class,
'html_template' => 'Hello, {{ name }}. Your role is {{ role }}.',
]);

$mailable = new BasicMail('John');
$mailable->setAdditionalData(['role' => 'admin']);

$renderedMail = $mailable->render();

$this->assertEquals('Hello, John. Your role is admin.', $renderedMail);
}
}

0 comments on commit 093eba4

Please sign in to comment.