Completed
Push — master ( 0da63d...5d60ca )
by Chris
30:45 queued 15:46
created

CryptoGuardTest::testFailedDecryption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 22
rs 9.2
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
class CryptoGuardTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    public function testEncryption()
7
    {
8
        require_once __DIR__ . '/../vendor/autoload.php';
9
10
        $passphrase = 'test-passphrase';
11
12
        $cryptoGuard = new \Coreproc\CryptoGuard\CryptoGuard($passphrase);
13
14
        $stringToEncrypt = 'test string to encrypt';
15
16
        $encryptedText = $cryptoGuard->encrypt($stringToEncrypt);
17
18
        $decryptedText = $cryptoGuard->decrypt($encryptedText);
19
20
        $this->assertEquals($stringToEncrypt, $decryptedText);
21
    }
22
23
    /**
24
     * @expectedException Coreproc\CryptoGuard\Exceptions\InvalidPayloadException
25
     */
26
    public function testFailedDecryption()
27
    {
28
        require_once __DIR__ . '/../vendor/autoload.php';
29
30
        $passphrase = 'test-passphrase';
31
32
        $cryptoGuard = new \Coreproc\CryptoGuard\CryptoGuard($passphrase);
33
34
        $stringToEncrypt = 'test string to encrypt';
35
36
        $encryptedText = $cryptoGuard->encrypt($stringToEncrypt);
37
38
        // decrypt the string
39
        $decryptedText = json_decode(base64_decode($encryptedText), true);
40
41
        $decryptedText['iv'] = 'changed-iv-for-test';
42
43
        // encrypt again
44
        $encryptedText = base64_encode(json_encode($decryptedText));
45
46
        $decryptedText = $cryptoGuard->decrypt($encryptedText);
0 ignored issues
show
Unused Code introduced by
$decryptedText is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
    }
48
49
}