Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

Tests/unit/Helper/Cipher/UrlSafeCipherTest.php (1 issue)

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 Tests\Kunstmaan\UtilitiesBundle\Helper\Cipher;
4
5
use Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * UrlSafeCipherTest
10
 */
11
class UrlSafeCipherTest extends TestCase
12
{
13
    const SECRET = 'secret';
14
    const CONTENT = 'This is a random sentence which will be encrypted and then decrypted!';
15
16
    /**
17
     * @var UrlSafeCipher
18
     */
19
    protected $cipher;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     *
25
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::__construct
26
     */
27
    protected function setUp()
28
    {
29
        $this->cipher = new UrlSafeCipher(self::SECRET);
30
    }
31
32
    /**
33
     * Tears down the fixture, for example, closes a network connection.
34
     * This method is called after a test is executed.
35
     */
36
    protected function tearDown()
37
    {
38
    }
39
40
    /**
41
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::encrypt
42
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::decrypt
43
     */
44 View Code Duplication
    public function testEncryptDecrypt()
45
    {
46
        $encryptedValue = $this->cipher->encrypt(self::CONTENT);
47
        $this->assertNotEquals(self::CONTENT, $encryptedValue);
48
        $decryptedValue = $this->cipher->decrypt($encryptedValue);
49
        $this->assertEquals($decryptedValue, self::CONTENT);
50
    }
51
52
    /**
53
     * @group legacy
54
     * @covers \Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::hex2bin
55
     */
56 View Code Duplication
    public function testHex2bin()
57
    {
58
        $hexValue = bin2hex(self::CONTENT);
59
        $this->assertNotEquals(self::CONTENT, $hexValue);
60
        $binValue = $this->cipher->hex2bin($hexValue);
0 ignored issues
show
Deprecated Code introduced by
The method Kunstmaan\UtilitiesBundl...rlSafeCipher::hex2bin() has been deprecated with message: The "Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::hex2bin" method is deprecated since KunstmaanUtilitiesBundle 5.5 and will be removed in KunstmaanUtilitiesBundle 6.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
61
        $this->assertEquals($binValue, self::CONTENT);
62
    }
63
64
    /**
65
     * @group legacy
66
     * @expectedDeprecation Overriding the "Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::hex2bin" method is deprecated since KunstmaanUtilitiesBundle 5.5 and the method will be removed in KunstmaanUtilitiesBundle 6.0. The "Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher" class will use the native hex2bin function instead.
67
     * @expectedDeprecation The "Kunstmaan\UtilitiesBundle\Helper\Cipher\UrlSafeCipher::hex2bin" method is deprecated since KunstmaanUtilitiesBundle 5.5 and will be removed in KunstmaanUtilitiesBundle 6.0.
68
     */
69
    public function testHex2binOverride()
70
    {
71
        $encryptedLetter = '6465663530323030326666656464313233623237656563366361666136306139303637663530626436623665356463326134363162326564646339643565353738643631633336663637626562316535353732393337643561656437653464373163643631383134613636303766626231366462376430393530616332346634636264636663663436333730333132303138303561393166616466616562366163613030366561643664';
72
        $decryptedLetter = 'a';
73
        $cipherOveride = new class(self::SECRET) extends UrlSafeCipher {
74
            public function hex2bin($hexString)
75
            {
76
                return parent::hex2bin($hexString);
77
            }
78
        };
79
80
        $decryptedResult = $cipherOveride->decrypt($encryptedLetter);
81
82
        $this->assertEquals($decryptedLetter, $decryptedResult);
83
    }
84
}
85