Skip to content

Commit 4cc9728

Browse files
author
Muhammad Umer Farooq
authored
Merge pull request #2 from peter279k/initialize_tests
Initialize tests
2 parents 0f5e8f9 + e3dc210 commit 4cc9728

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

composer.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,26 @@
99
"email":"lablnet01@gmail.com",
1010
"homepage": "https://softhub99.com"
1111
}
12-
],
12+
],
13+
"require": {
14+
"php": "^7.1",
15+
"ext-mbstring": "*"
16+
},
17+
"require-dev": {
18+
"phpunit/phpunit": "^7.0"
19+
},
20+
"suggest": {
21+
"ext-openssl": "This is for the OpenSSL encryption",
22+
"ext-sodium": "This is for the Sodium encryption"
23+
},
1324
"autoload": {
1425
"psr-4": {
15-
"Lablnet\\": "src/"
26+
"Lablnet\\": "src/"
27+
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"Lablnet\\Tests\\": "tests/"
1632
}
1733
}
18-
}
34+
}

phpunit.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="Unit Tests">
13+
<directory suffix="Test.php">./tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist>
18+
<directory suffix=".php">src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

tests/EncryptionTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/**
4+
* This file is the Encryption test.
5+
*
6+
* @author Peter279k <peter279k@gmail.com>
7+
* @author-profile https://peterli.website/
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*
12+
* @note This file is not a part of Zest Framework.
13+
*
14+
* @license MIT
15+
*/
16+
17+
namespace Lablnet\Tests;
18+
19+
use Lablnet\Encryption;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class EncryptionTest extends TestCase
23+
{
24+
public function testEncryptAndDecryptWithOpenSsl()
25+
{
26+
$encryption = new Encryption('12345678990-=====-===','openssl');
27+
$encryptedString = $encryption->encrypt('plain-text');
28+
$decryptedString = $encryption->decrypt($encryptedString);
29+
30+
$this->assertStringEndsWith('==', $encryptedString);
31+
$this->assertSame(80, strlen($encryptedString));
32+
$this->assertSame('plain-text', $decryptedString);
33+
}
34+
35+
public function testEncryptAndDecryptWithSodium()
36+
{
37+
$encryption = new Encryption('euyq74tjfdskjFDSGq74','sodium');
38+
$encryptedString = $encryption->encrypt('plain-text');
39+
$decryptedString = $encryption->decrypt($encryptedString);
40+
41+
$this->assertStringEndsWith('==', $encryptedString);
42+
$this->assertSame(80, strlen($encryptedString));
43+
$this->assertSame('plain-text', $decryptedString);
44+
}
45+
}

0 commit comments

Comments
 (0)