Added EmailService
This commit is contained in:
parent
7be8061aa8
commit
538b88952e
2 changed files with 42 additions and 0 deletions
14
src/Services/EmailService.php
Normal file
14
src/Services/EmailService.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
|
||||
class EmailService
|
||||
{
|
||||
public function validateEmail($email)
|
||||
{
|
||||
if (!$email)
|
||||
return;
|
||||
|
||||
if (!preg_match('/^[^@]+@[^@]+\.\w+$/', $email))
|
||||
throw new \DomainException('Specified e-mail appears to be invalid.');
|
||||
}
|
||||
}
|
28
tests/Services/EmailServiceTest.php
Normal file
28
tests/Services/EmailServiceTest.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests\Services;
|
||||
|
||||
class EmailServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testEmailWithoutAt()
|
||||
{
|
||||
$emailService = new \Szurubooru\Services\EmailService();
|
||||
|
||||
$this->setExpectedException(\DomainException::class);
|
||||
$emailService->validateEmail('ghost');
|
||||
}
|
||||
|
||||
public function testEmailWithoutDotInDomain()
|
||||
{
|
||||
$emailService = new \Szurubooru\Services\EmailService();
|
||||
|
||||
$this->setExpectedException(\DomainException::class);
|
||||
$emailService->validateEmail('ghost@cemetery');
|
||||
}
|
||||
|
||||
public function testValidEmail()
|
||||
{
|
||||
$emailService = new \Szurubooru\Services\EmailService();
|
||||
|
||||
$this->assertNull($emailService->validateEmail('ghost@cemetery.consulting'));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue