Completed
Pull Request — master (#2)
by Eugene
02:20
created

testDecryptFromWrongEmailFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.9332
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Azine\EmailUpdateConfirmationBundle\Tests;
4
5
use Azine\EmailUpdateConfirmationBundle\Services\EmailEncryption;
6
use Symfony\Component\Validator\ConstraintViolationList;
7
use Symfony\Component\Validator\Validator\ValidatorInterface;
8
9
class EmailEncryptionTest extends \PHPUnit_Framework_TestCase
10
{
11
    /** @var ValidatorInterface */
12
    private $emailValidator;
13
    /** @var ConstraintViolationList */
14
    private $constraintViolationList;
15
16
    protected function setUp()
17
    {
18
        $this->emailValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')->disableOriginalConstructor()->getMock();
19
        $this->constraintViolationList = new ConstraintViolationList(array($this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')->disableOriginalConstructor()->getMock()));
20
    }
21
22
    /**
23
     * @expectedException \InvalidArgumentException
24
     */
25
    public function testIntegerIsSetInsteadOfEmailString()
26
    {
27
        $emailEncryption = new EmailEncryption($this->emailValidator);
28
        $emailEncryption->setEmail(123);
29
    }
30
31
    /**
32
     * @expectedException \InvalidArgumentException
33
     */
34
    public function testIntegerIsSetInsteadOfConfirmationTokenString()
35
    {
36
        $emailEncryption = new EmailEncryption($this->emailValidator);
37
        $emailEncryption->setUserConfirmationToken(123);
38
    }
39
40
    /**
41
     * @expectedException \InvalidArgumentException
42
     */
43
    public function testNullIsSetInsteadOfConfirmationTokenString()
44
    {
45
        $emailEncryption = new EmailEncryption($this->emailValidator);
46
        $emailEncryption->setUserConfirmationToken(null);
47
    }
48
49
    public function testGetConfirmationToken()
50
    {
51
        $this->constraintViolationList->remove(0);
52
        $emailEncryption = new EmailEncryption($this->emailValidator);
53
        $emailEncryption->setUserConfirmationToken('test_token');
54
55
        $confirmationToken = $emailEncryption->getConfirmationToken();
56
        $expectedConfirmationToken = pack('H*', hash('sha256', 'test_token'));
57
        $this->assertSame($expectedConfirmationToken, $confirmationToken);
58
    }
59
60
    /**
61
     * @expectedException \InvalidArgumentException
62
     */
63
    public function testGetConfirmationTokenIfUserConfirmationTokenIsNotSet()
64
    {
65
        $emailEncryption = new EmailEncryption($this->emailValidator);
66
        $emailEncryption->getConfirmationToken();
67
    }
68
}
69