Test Failed
Push — master ( dde0ed...e2b526 )
by Francesco
03:04
created

testDecryptResourceWithPasswordThrowsException()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the MesCryptoBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mes\Security\CryptoBundle\Tests;
13
14
use Defuse\Crypto\Exception\CryptoException as BaseCryptoException;
15
use Mes\Security\CryptoBundle\EncryptionWrapper;
16
use Mes\Security\CryptoBundle\Exception\CryptoException;
17
18
/**
19
 * Class EncryptionResourceWrapperTest.
20
 */
21
class EncryptionResourceWrapperTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var EncryptionWrapper
25
     */
26
    private $wrapper;
27
28
    /**
29
     * @var \PHPUnit_Framework_MockObject_MockObject
30
     */
31
    private $encryption;
32
33
    protected function setUp()
34
    {
35
        $this->encryption = $this->getMockBuilder('Mes\Security\CryptoBundle\EncryptionInterface')
36
                                 ->getMock();
37
        $this->wrapper = new EncryptionWrapper($this->encryption);
38
    }
39
40
    protected function tearDown()
41
    {
42
        $this->wrapper = null;
43
        $this->encryption = null;
44
    }
45
46
    /* ===========================================
47
     *
48
     * EncryptionInterface::EncryptResourceWithKey
49
     *
50
     * ===========================================
51
     */
52
53
    /**
54
     * @throws CryptoException
55
     */
56 View Code Duplication
    public function testEncryptResourceWithKeyEncryptsHandle()
0 ignored issues
show
Duplication introduced by
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...
57
    {
58
        $this->encryption->expects($this->once())
59
                         ->method('encryptResourceWithKey');
60
61
        $this->wrapper->encryptResourceWithKey(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface')
0 ignored issues
show
Bug introduced by
The method encryptResourceWithKey() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
                                                                                                            ->getMock());
63
    }
64
65
    /**
66
     * @throws CryptoException
67
     */
68 View Code Duplication
    public function testDecryptResourceWithKeyDecryptsEncryptedHandle()
0 ignored issues
show
Duplication introduced by
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...
69
    {
70
        $this->encryption->expects($this->once())
71
                         ->method('decryptResourceWithKey');
72
73
        $this->wrapper->decryptResourceWithKey(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface')
0 ignored issues
show
Bug introduced by
The method decryptResourceWithKey() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
74
                                                                                                            ->getMock());
75
    }
76
77
    /**
78
     * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException
79
     */
80 View Code Duplication
    public function testEncryptResourceWithKeyThrowsException()
0 ignored issues
show
Duplication introduced by
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...
81
    {
82
        try {
83
            $this->encryption->expects($this->once())
84
                             ->method('encryptResourceWithKey')
85
                             ->will($this->throwException(new BaseCryptoException()));
86
        } catch (BaseCryptoException $e) {
87
            $this->throwException(new CryptoException());
88
        }
89
90
        $this->wrapper->encryptResourceWithKey(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface')
0 ignored issues
show
Bug introduced by
The method encryptResourceWithKey() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
                                                                                                            ->getMock());
92
    }
93
94
    /**
95
     * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException
96
     */
97 View Code Duplication
    public function testDecryptResourceWithKeyThrowsException()
0 ignored issues
show
Duplication introduced by
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...
98
    {
99
        try {
100
            $this->encryption->expects($this->once())
101
                             ->method('decryptResourceWithKey')
102
                             ->will($this->throwException(new BaseCryptoException()));
103
        } catch (BaseCryptoException $e) {
104
            $this->throwException(new CryptoException());
105
        }
106
107
        $this->wrapper->decryptResourceWithKey(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), $this->getMockBuilder('Mes\Security\CryptoBundle\Model\KeyInterface')
0 ignored issues
show
Bug introduced by
The method decryptResourceWithKey() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
                                                                                                            ->getMock());
109
    }
110
111
    /* ================================================
112
     *
113
     * EncryptionInterface::EncryptResourceWithPassword
114
     *
115
     * ================================================
116
     */
117
118
    /**
119
     * @throws CryptoException
120
     */
121 View Code Duplication
    public function testEncryptResourceWithPasswordEncryptsHandle()
0 ignored issues
show
Duplication introduced by
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...
122
    {
123
        $this->encryption->expects($this->once())
124
                         ->method('encryptResourceWithPassword');
125
126
        $this->wrapper->encryptResourceWithPassword(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), 'SecretPa$$word');
0 ignored issues
show
Bug introduced by
The method encryptResourceWithPassword() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
    }
128
129
    /**
130
     * @throws CryptoException
131
     */
132 View Code Duplication
    public function testDecryptResourceWithPasswordDecryptsEncryptedHandle()
0 ignored issues
show
Duplication introduced by
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...
133
    {
134
        $this->encryption->expects($this->once())
135
                         ->method('decryptResourceWithPassword');
136
137
        $this->wrapper->decryptResourceWithPassword(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), 'SecretPa$$word');
0 ignored issues
show
Bug introduced by
The method decryptResourceWithPassword() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
138
    }
139
140
    /**
141
     * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException
142
     */
143 View Code Duplication
    public function testEncryptResourceWithPasswordThrowsException()
0 ignored issues
show
Duplication introduced by
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...
144
    {
145
        try {
146
            $this->encryption->expects($this->once())
147
                             ->method('encryptResourceWithPassword')
148
                             ->will($this->throwException(new BaseCryptoException()));
149
        } catch (BaseCryptoException $e) {
150
            $this->throwException(new CryptoException());
151
        }
152
153
        $this->wrapper->encryptResourceWithPassword(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), 'SecretPa$$word');
0 ignored issues
show
Bug introduced by
The method encryptResourceWithPassword() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
    }
155
156
    /**
157
     * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException
158
     */
159 View Code Duplication
    public function testDecryptResourceWithPasswordThrowsException()
0 ignored issues
show
Duplication introduced by
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...
160
    {
161
        try {
162
            $this->encryption->expects($this->once())
163
                             ->method('decryptResourceWithPassword')
164
                             ->will($this->throwException(new BaseCryptoException()));
165
        } catch (BaseCryptoException $e) {
166
            $this->throwException(new CryptoException());
167
        }
168
169
        $this->wrapper->decryptResourceWithPassword(fopen('php://stdin', 'r'), fopen('php://memory', 'wb'), 'SecretPa$$word');
0 ignored issues
show
Bug introduced by
The method decryptResourceWithPassword() does not seem to exist on object<Mes\Security\Cryp...ndle\EncryptionWrapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
170
    }
171
}
172