Completed
Push — master ( 6ceb07...e22522 )
by Sergei
16:21
created

Tests/Unit/Service/MailServiceTest.php (2 issues)

not multiple classes are defined in the same file.

Coding Style Compatibility Minor

Upgrade to new PHP Analysis Engine

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'));
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
44
{
45
    public function findOneBy()
46
    {
47
        return;
48
    }
49
}
50
51
class DummySwiftMailer extends \Swift_Mailer
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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