Completed
Push — master ( c3ca4d...7a4819 )
by Dominik
06:54
created

Tests/Services/EmailUpdateConfirmationTest.php (1 issue)

Labels
Severity

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 Azine\EmailUpdateConfirmationBundle\Tests;
4
5
use FOS\UserBundle\Mailer\MailerInterface;
6
use FOS\UserBundle\Model\User;
7
use Azine\EmailUpdateConfirmationBundle\Services\EmailEncryption;
8
use Azine\EmailUpdateConfirmationBundle\Services\EmailUpdateConfirmation;
9
use FOS\UserBundle\Util\TokenGenerator;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\EventDispatcher\EventDispatcher;
12
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
13
use Symfony\Component\Routing\RouterInterface;
14
use Symfony\Component\Validator\ConstraintViolationList;
15
use Symfony\Component\Validator\Validator\ValidatorInterface;
16
17
class EmailUpdateConfirmationTest extends TestCase
18
{
19
    /** @var ExpressionFunctionProviderInterface */
20
    private $provider;
21
    /** @var RouterInterface */
22
    private $router;
23
    /** @var TokenGenerator */
24
    private $tokenGenerator;
25
    /** @var MailerInterface */
26
    private $mailer;
27
    /** @var EmailEncryption */
28
    private $emailEncryption;
29
    /** @var EventDispatcher */
30
    private $eventDispatcher;
31
    /** @var EmailUpdateConfirmation */
32
    private $emailUpdateConfirmation;
33
    /** @var User */
34
    private $user;
35
    private $cypher_method = 'AES-128-CBC';
36
37
    /** @var ValidatorInterface */
38
    private $emailValidator;
39
    /** @var ConstraintViolationList */
40
    private $constraintViolationList;
41
42
    protected function setUp()
43
    {
44
        $this->emailValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')->disableOriginalConstructor()->getMock();
45
        $this->constraintViolationList = new ConstraintViolationList(array());
46
        $this->emailValidator->expects($this->once())->method('validate')->will($this->returnValue($this->constraintViolationList));
47
48
        $this->provider = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface')->getMock();
49
        $this->user = $this->getMockBuilder('FOS\UserBundle\Model\User')
50
            ->disableOriginalConstructor()
51
            ->getMock();
52
        $this->router = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Routing\Router')
53
            ->disableOriginalConstructor()
54
            ->getMock();
55
56
        $this->tokenGenerator = $this->getMockBuilder('FOS\UserBundle\Util\TokenGenerator')->disableOriginalConstructor()->getMock();
57
        $this->mailer = $this->getMockBuilder('Azine\EmailUpdateConfirmationBundle\Mailer\AzineUpdateEmailMailer')->disableOriginalConstructor()->getMock();
58
        $this->emailEncryption = new EmailEncryption($this->emailValidator, $this->cypher_method);
59
        $this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
60
61
        $this->emailUpdateConfirmation = new EmailUpdateConfirmation($this->router, $this->tokenGenerator, $this->mailer, $this->emailEncryption, $this->eventDispatcher);
0 ignored issues
show
The call to EmailUpdateConfirmation::__construct() misses a required argument $redirectRoute.

This check looks for function calls that miss required arguments.

Loading history...
62
        $this->user->expects($this->any())
63
            ->method('getConfirmationToken')
64
            ->will($this->returnValue('test_token'));
65
        $this->emailUpdateConfirmation->setUser($this->user);
66
    }
67
68
    public function testFetchEncryptedEmailFromConfirmationLinkMethod()
69
    {
70
        $emailEncryption = new EmailEncryption($this->emailValidator, $this->cypher_method);
71
        $emailEncryption->setEmail('[email protected]');
72
        $emailEncryption->setUserConfirmationToken('test_token');
73
74
        $encryptedEmail = $emailEncryption->encryptEmailValue();
75
76
        $email = $this->emailUpdateConfirmation->fetchEncryptedEmailFromConfirmationLink($encryptedEmail);
77
        $this->assertSame('[email protected]', $email);
78
    }
79
}