Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@
"email":"lablnet01@gmail.com",
"homepage": "https://softhub99.com"
}
],
],
"require": {
"php": "^7.1",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"suggest": {
"ext-openssl": "This is for the OpenSSL encryption",
"ext-sodium": "This is for the Sodium encryption"
},
"autoload": {
"psr-4": {
"Lablnet\\": "src/"
"Lablnet\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Lablnet\\Tests\\": "tests/"
}
}
}
}
21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit Tests">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
45 changes: 45 additions & 0 deletions tests/EncryptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This file is the Encryption test.
*
* @author Peter279k <peter279k@gmail.com>
* @author-profile https://peterli.website/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @note This file is not a part of Zest Framework.
*
* @license MIT
*/

namespace Lablnet\Tests;

use Lablnet\Encryption;
use PHPUnit\Framework\TestCase;

class EncryptionTest extends TestCase
{
public function testEncryptAndDecryptWithOpenSsl()
{
$encryption = new Encryption('12345678990-=====-===','openssl');
$encryptedString = $encryption->encrypt('plain-text');
$decryptedString = $encryption->decrypt($encryptedString);

$this->assertStringEndsWith('==', $encryptedString);
$this->assertSame(80, strlen($encryptedString));
$this->assertSame('plain-text', $decryptedString);
}

public function testEncryptAndDecryptWithSodium()
{
$encryption = new Encryption('euyq74tjfdskjFDSGq74','sodium');
$encryptedString = $encryption->encrypt('plain-text');
$decryptedString = $encryption->decrypt($encryptedString);

$this->assertStringEndsWith('==', $encryptedString);
$this->assertSame(80, strlen($encryptedString));
$this->assertSame('plain-text', $decryptedString);
}
}