1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modera\BackendSecurityBundle\Tests\Unit\Service; |
4
|
|
|
|
5
|
|
|
use Modera\SecurityBundle\Entity\User; |
6
|
|
|
use Modera\BackendSecurityBundle\Service\MailService; |
7
|
|
|
use Modera\BackendLanguagesBundle\Entity\UserSettings; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Sergei Vizel <[email protected]> |
11
|
|
|
* @copyright 2014 Modera Foundation |
12
|
|
|
*/ |
13
|
|
|
class MailServiceTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
private $em; |
16
|
|
|
private $mailer; |
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->em = \Phake::mock('Doctrine\ORM\EntityManagerInterface'); |
21
|
|
|
\Phake::when($this->em)->getRepository(UserSettings::clazz())->thenReturn(new DummyRepository()); |
22
|
|
|
|
23
|
|
|
$this->mailer = new DummySwiftMailer(\Phake::mock('Swift_Transport')); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function testSuccessfulSendPassword() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$ms = new MailService($this->em, $this->mailer, 'en', 'no-reply@no-reply'); |
|
|
|
|
29
|
|
|
$user = new User(); |
30
|
|
|
$user->setEmail('[email protected]'); |
31
|
|
|
$this->assertTrue($ms->sendPassword($user, 'password')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testFailureSendPassword() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$ms = new MailService($this->em, $this->mailer, 'en', 'no-reply@no-reply'); |
|
|
|
|
37
|
|
|
$user = new User(); |
38
|
|
|
$user->setEmail('[email protected]'); |
39
|
|
|
$this->assertTrue(is_array($ms->sendPassword($user, 'password'))); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
class DummyRepository |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
public function findOneBy() |
46
|
|
|
{ |
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
class DummySwiftMailer extends \Swift_Mailer |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
public function createMessage($service = 'message') |
54
|
|
|
{ |
55
|
|
|
return \Swift_Message::newInstance(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function send(\Swift_Mime_Message $message, &$failedRecipients = null) |
59
|
|
|
{ |
60
|
|
|
if (in_array('[email protected]', array_keys($message->getTo()))) { |
61
|
|
|
return 0; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return 1; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: