Skip to content

Commit

Permalink
Merge pull request #721 from wmde/mailv
Browse files Browse the repository at this point in the history
Catch empty domain in EmailAddress constructor
  • Loading branch information
gbirke committed Oct 24, 2016
2 parents baccfc5 + fdaa331 commit 84c27d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions contexts/MembershipContext/src/Domain/Model/EmailAddress.php
Expand Up @@ -23,6 +23,10 @@ public function __construct( string $emailAddress ) {

$this->userName = $addressParts[0];
$this->domain = $addressParts[1];

if ( trim( $this->domain ) === '' ) {
throw new \InvalidArgumentException( 'Email domain cannot be empty' );
}
}

public function getUserName(): string {
Expand Down
Expand Up @@ -2,7 +2,7 @@

declare( strict_types = 1 );

namespace WMDE\Fundraising\Frontend\Tests\Unit\MembershipContext\Domain\Model;
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Unit\Domain\Model;

use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress;

Expand All @@ -11,6 +11,7 @@
*
* @licence GNU GPL v2+
* @author Kai Nissen < kai.nissen@wikimedia.de >
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class EmailAddressTest extends \PHPUnit_Framework_TestCase {

Expand All @@ -33,6 +34,11 @@ public function unparsableAddressProvider() {
];
}

public function testWhenDomainIsEmpty_constructorThrowsException() {
$this->expectException( \InvalidArgumentException::class );
new EmailAddress( 'jeroendedauw@' );
}

public function testGetFullAddressReturnsOriginalInput() {
$email = new EmailAddress( 'jeroendedauw@gmail.com' );

Expand Down

0 comments on commit 84c27d6

Please sign in to comment.