Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddressTest.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mime\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Mime\Address;
  13. use Symfony\Component\Mime\NamedAddress;
  14. class AddressTest extends TestCase
  15. {
  16. public function testConstructor()
  17. {
  18. $a = new Address('fabien@symfonï.com');
  19. $this->assertEquals('fabien@symfonï.com', $a->getAddress());
  20. $this->assertEquals('fabien@xn--symfon-nwa.com', $a->toString());
  21. $this->assertEquals('fabien@xn--symfon-nwa.com', $a->getEncodedAddress());
  22. }
  23. public function testConstructorWithInvalidAddress()
  24. {
  25. $this->expectException(\InvalidArgumentException::class);
  26. new Address('fab pot@symfony.com');
  27. }
  28. public function testCreate()
  29. {
  30. $this->assertSame($a = new Address('fabien@symfony.com'), Address::create($a));
  31. $this->assertSame($b = new NamedAddress('helene@symfony.com', 'Helene'), Address::create($b));
  32. $this->assertEquals($a, Address::create('fabien@symfony.com'));
  33. }
  34. public function testCreateWrongArg()
  35. {
  36. $this->expectException(\InvalidArgumentException::class);
  37. Address::create(new \stdClass());
  38. }
  39. public function testCreateArray()
  40. {
  41. $fabien = new Address('fabien@symfony.com');
  42. $helene = new NamedAddress('helene@symfony.com', 'Helene');
  43. $this->assertSame([$fabien, $helene], Address::createArray([$fabien, $helene]));
  44. $this->assertEquals([$fabien], Address::createArray(['fabien@symfony.com']));
  45. }
  46. public function testCreateArrayWrongArg()
  47. {
  48. $this->expectException(\InvalidArgumentException::class);
  49. Address::createArray([new \stdClass()]);
  50. }
  51. }