Completed
Pull Request — master (#721)
by Jeroen De
49:51
created

testWhenGivenMail_validatorMXValidatesCorrectly()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Unit\Domain\Model;
6
7
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;
8
9
/**
10
 * @covers WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Kai Nissen < [email protected] >
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class EmailAddressTest extends \PHPUnit_Framework_TestCase {
17
18
	/**
19
	 * @dataProvider unparsableAddressProvider
20
	 */
21
	public function testWhenGivenMail_validatorMXValidatesCorrectly( $mailToTest ) {
22
		$this->expectException( \InvalidArgumentException::class );
23
		$this->expectExceptionMessage( 'Given email address could not be parsed' );
24
25
		new EmailAddress( $mailToTest );
26
	}
27
28
	public function unparsableAddressProvider() {
29
		return [
30
			[ 'just.testing' ],
31
			[ 'can.you@deliver@this' ],
32
			[ '' ],
33
			[ ' ' ]
34
		];
35
	}
36
37
	public function testWhenDomainIsEmpty_constructorThrowsException() {
38
		$this->expectException( \InvalidArgumentException::class );
39
		new EmailAddress( 'jeroendedauw@' );
40
	}
41
42
	public function testGetFullAddressReturnsOriginalInput() {
43
		$email = new EmailAddress( '[email protected]' );
44
45
		$this->assertSame( '[email protected]', $email->getFullAddress() );
46
	}
47
48
	public function testCanGetEmailParts() {
49
		$email = new EmailAddress( '[email protected]' );
50
51
		$this->assertSame( 'jeroendedauw', $email->getUserName() );
52
		$this->assertSame( 'gmail.com', $email->getDomain() );
53
	}
54
55
	public function testCanNormalizedDomainName() {
56
		$email = new EmailAddress( 'info@triebwerk-grün.de' );
57
58
		$this->assertSame( 'xn--triebwerk-grn-7ob.de', $email->getNormalizedDomain() );
59
		$this->assertSame( '[email protected]', $email->getNormalizedAddress() );
60
	}
61
62
	public function testToStringOriginalInput() {
63
		$email = new EmailAddress( '[email protected]' );
64
65
		$this->assertSame( '[email protected]', (string)$email->getFullAddress() );
66
	}
67
68
}
69