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

EmailAddressTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 53
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testWhenGivenMail_validatorMXValidatesCorrectly() 0 6 1
A unparsableAddressProvider() 0 8 1
A testWhenDomainIsEmpty_constructorThrowsException() 0 4 1
A testGetFullAddressReturnsOriginalInput() 0 5 1
A testCanGetEmailParts() 0 6 1
A testCanNormalizedDomainName() 0 6 1
A testToStringOriginalInput() 0 5 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