|
| 1 | +<?php |
| 2 | + |
| 3 | +class ToSwiftmailerEmailsTest extends TestCase |
| 4 | +{ |
| 5 | + /** @test */ |
| 6 | + public function it_returns_an_empty_array_for_empty_array() |
| 7 | + { |
| 8 | + $this->assertEquals([], to_swiftmailer_emails([])); |
| 9 | + } |
| 10 | + |
| 11 | + /** @test */ |
| 12 | + public function it_supports_simplified_syntax_for_one_email() |
| 13 | + { |
| 14 | + $this->assertEquals( |
| 15 | + ['john.doe@example.com' => 'John Doe'], |
| 16 | + to_swiftmailer_emails(['address' => 'john.doe@example.com', 'name' => 'John Doe']) |
| 17 | + ); |
| 18 | + } |
| 19 | + |
| 20 | + /** @test */ |
| 21 | + public function it_supports_multiple_emails() |
| 22 | + { |
| 23 | + $this->assertEquals( |
| 24 | + [ |
| 25 | + 'john.doe@example.com' => 'John Doe', |
| 26 | + 'jane.doe@example.com' => 'Jane Doe', |
| 27 | + 'mary.doe@example.com' => 'Mary Doe', |
| 28 | + ], |
| 29 | + to_swiftmailer_emails([ |
| 30 | + ['address' => 'john.doe@example.com', 'name' => 'John Doe'], |
| 31 | + ['address' => 'jane.doe@example.com', 'name' => 'Jane Doe'], |
| 32 | + ['address' => 'mary.doe@example.com', 'name' => 'Mary Doe'], |
| 33 | + ]) |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + /** @test */ |
| 38 | + public function it_skips_items_with_empty_addresses() |
| 39 | + { |
| 40 | + $this->assertEquals( |
| 41 | + [ |
| 42 | + 'john.doe@example.com' => 'John Doe', |
| 43 | + 'mary.doe@example.com' => 'Mary Doe', |
| 44 | + ], |
| 45 | + to_swiftmailer_emails([ |
| 46 | + ['address' => 'john.doe@example.com', 'name' => 'John Doe'], |
| 47 | + ['address' => null, 'name' => 'Jane Doe'], |
| 48 | + ['address' => false, 'name' => 'Jane Doe'], |
| 49 | + ['address' => '', 'name' => 'Jane Doe'], |
| 50 | + ['address' => 'mary.doe@example.com', 'name' => 'Mary Doe'], |
| 51 | + ['name' => 'Jane Doe'], |
| 52 | + ]) |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + /** @test */ |
| 57 | + public function it_skips_items_with_invalid_addresses() |
| 58 | + { |
| 59 | + $this->assertEquals( |
| 60 | + [ |
| 61 | + 'john.doe@example.com' => 'John Doe', |
| 62 | + 'jane.doe@example.com' => 'Jane Doe', |
| 63 | + ], |
| 64 | + to_swiftmailer_emails([ |
| 65 | + ['address' => 'john.doe@example.com', 'name' => 'John Doe'], |
| 66 | + ['address' => 'mary.doe', 'name' => 'Mary Doe'], |
| 67 | + ['address' => 'mary.doe@', 'name' => 'Mary Doe'], |
| 68 | + ['address' => 'mary.doe@example', 'name' => 'Mary Doe'], |
| 69 | + ['address' => 'mary.doe@example.', 'name' => 'Mary Doe'], |
| 70 | + ['address' => 'jane.doe@example.com', 'name' => 'Jane Doe'], |
| 71 | + ]) |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + /** @test */ |
| 76 | + public function name_is_optional_for_one_email() |
| 77 | + { |
| 78 | + $this->assertEquals(['john.doe@example.com'], to_swiftmailer_emails(['address' => 'john.doe@example.com'])); |
| 79 | + } |
| 80 | + |
| 81 | + /** @test */ |
| 82 | + public function name_is_optional_for_multiple_emails() |
| 83 | + { |
| 84 | + $this->assertEquals( |
| 85 | + [ |
| 86 | + 'john.doe@example.com', |
| 87 | + 'jane.doe@example.com' => 'Jane Doe', |
| 88 | + 'mary.doe@example.com', |
| 89 | + ], |
| 90 | + to_swiftmailer_emails([ |
| 91 | + ['address' => 'john.doe@example.com'], |
| 92 | + ['address' => 'jane.doe@example.com', 'name' => 'Jane Doe'], |
| 93 | + ['address' => 'mary.doe@example.com'], |
| 94 | + ]) |
| 95 | + ); |
| 96 | + } |
| 97 | +} |
0 commit comments