These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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')); |
||
0 ignored issues
–
show
|
|||
24 | } |
||
25 | |||
26 | View Code Duplication | public function testSuccessfulSendPassword() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
27 | { |
||
28 | $ms = new MailService($this->em, $this->mailer, 'en', 'no-reply@no-reply'); |
||
0 ignored issues
–
show
$this->em is of type object<Phake_IMock> , but the function expects a object<Doctrine\ORM\EntityManagerInterface> .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
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() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
35 | { |
||
36 | $ms = new MailService($this->em, $this->mailer, 'en', 'no-reply@no-reply'); |
||
0 ignored issues
–
show
$this->em is of type object<Phake_IMock> , but the function expects a object<Doctrine\ORM\EntityManagerInterface> .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
37 | $user = new User(); |
||
38 | $user->setEmail('[email protected]'); |
||
39 | $this->assertTrue(is_array($ms->sendPassword($user, 'password'))); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | class DummyRepository |
||
0 ignored issues
–
show
|
|||
44 | { |
||
45 | public function findOneBy() |
||
46 | { |
||
47 | return; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | class DummySwiftMailer extends \Swift_Mailer |
||
0 ignored issues
–
show
|
|||
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: