-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
142 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,7 @@ Laravel-specific and pure PHP Helper Functions. | |
- [is_email](#is_email) | ||
- [to_rfc2822_email](#to_rfc2822_email) | ||
- [to_swiftmailer_emails](#to_swiftmailer_emails) | ||
- [to_symfony_emails](#to_symfony_emails) | ||
- [Filesystem](#filesystem) | ||
- [relative_path](#relative_path) | ||
|
@@ -295,10 +296,10 @@ Convert addresses data to [RFC 2822](http://faqs.org/rfcs/rfc2822.html) string, | |
```php | ||
to_rfc2822_email([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => 'mary[email protected]'], | ||
['address' => 'jane[email protected]'], | ||
]); | ||
// "John Doe <[email protected]>, mary[email protected]" | ||
// "John Doe <[email protected]>, jane[email protected]" | ||
``` | ||
Also, it supports simplified syntax for a single address: | ||
|
@@ -316,10 +317,10 @@ Convert addresses data to [SwiftMailer-suitable format](https://swiftmailer.org/ | |
```php | ||
to_swiftmailer_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => 'mary[email protected]'], | ||
['address' => 'jane[email protected]'], | ||
]); | ||
// ["[email protected]" => "John Doe", "mary[email protected]"] | ||
// ["[email protected]" => "John Doe", "jane[email protected]"] | ||
``` | ||
Also, it supports simplified syntax for a single address: | ||
|
@@ -330,6 +331,27 @@ to_swiftmailer_emails(['address' => '[email protected]', 'name' => 'John Doe' | |
// ["[email protected]" => "John Doe"] | ||
``` | ||
#### `to_symfony_emails()` | ||
Convert addresses data to [Symfony-suitable format](https://symfony.com/doc/current/mailer.html#email-addresses): | ||
```php | ||
to_symfony_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => '[email protected]'], | ||
]); | ||
// ["John Doe <[email protected]>", "[email protected]"] | ||
``` | ||
Also, it supports simplified syntax for a single address: | ||
```php | ||
to_symfony_emails(['address' => '[email protected]', 'name' => 'John Doe']); | ||
// ["John Doe <[email protected]>"] | ||
``` | ||
## Filesystem | ||
#### `relative_path()` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Illuminated\Helpers\Tests\Email; | ||
|
||
use Illuminated\Helpers\Tests\TestCase; | ||
|
||
class ToSymfonyEmailsTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_an_empty_array_for_an_empty_array() | ||
{ | ||
$this->assertEquals([], to_symfony_emails([])); | ||
} | ||
|
||
/** @test */ | ||
public function it_supports_simplified_syntax_for_one_email() | ||
{ | ||
$this->assertEquals( | ||
['John Doe <[email protected]>'], | ||
to_symfony_emails(['address' => '[email protected]', 'name' => 'John Doe']), | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_supports_multiple_emails() | ||
{ | ||
$this->assertEquals( | ||
['John Doe <[email protected]>', 'Jane Doe <[email protected]>', 'Mary Doe <[email protected]>'], | ||
to_symfony_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => '[email protected]', 'name' => 'Jane Doe'], | ||
['address' => '[email protected]', 'name' => 'Mary Doe'], | ||
]), | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_skips_items_with_empty_addresses() | ||
{ | ||
$this->assertEquals( | ||
['John Doe <[email protected]>', 'Mary Doe <[email protected]>'], | ||
to_symfony_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => null, 'name' => 'Jane Doe'], | ||
['address' => false, 'name' => 'Jane Doe'], | ||
['address' => '', 'name' => 'Jane Doe'], | ||
['name' => 'Fake Doe'], | ||
['address' => '[email protected]', 'name' => 'Mary Doe'], | ||
]), | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_skips_items_with_invalid_addresses() | ||
{ | ||
$this->assertEquals( | ||
['John Doe <[email protected]>', 'Vicky Doe <[email protected]>'], | ||
to_symfony_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => 'jane@', 'name' => 'Jane Doe'], | ||
['address' => 'jane@example', 'name' => 'Jane Doe'], | ||
['address' => '[email protected]', 'name' => 'Vicky Doe'], | ||
['address' => null, 'name' => 'Jane Doe'], | ||
]), | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function name_is_optional_for_one_email() | ||
{ | ||
$this->assertEquals(['[email protected]'], to_symfony_emails(['address' => '[email protected]'])); | ||
} | ||
|
||
/** @test */ | ||
public function name_is_optional_for_multiple_emails() | ||
{ | ||
$this->assertEquals( | ||
['John Doe <[email protected]>', '[email protected]', '[email protected]'], | ||
to_symfony_emails([ | ||
['address' => '[email protected]', 'name' => 'John Doe'], | ||
['address' => '[email protected]'], | ||
['address' => '[email protected]'], | ||
]), | ||
); | ||
} | ||
} |