Skip to content

Commit 9f0f90b

Browse files
Merge pull request #5 from koenhoeijmakers/unit
Added Unit Tests
2 parents 0452faf + c107973 commit 9f0f90b

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea
22
/vendor
3+
composer.lock

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "Argon2 implementation",
44
"require": {
55
"php": "^7.2",
6-
"illuminate/hashing": "5.0 - 5.5"
6+
"illuminate/hashing": "5.0 - 5.5",
7+
"phpunit/phpunit": "^7.0"
78
},
89
"license": "MIT",
910
"authors": [
@@ -16,5 +17,10 @@
1617
"psr-4": {
1718
"KoenHoeijmakers\\LaravelArgon2\\": "src/"
1819
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"KoenHoeijmakers\\LaravelArgon2\\Tests\\": "tests/"
24+
}
1925
}
2026
}

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
>
12+
<testsuites>
13+
<testsuite name="Laravel Argon2 test suite">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

tests/Unit/Argon2HasherTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace KoenHoeijmakers\LaravelArgon2\Tests\Unit;
4+
5+
use KoenHoeijmakers\LaravelArgon2\Argon2Hasher;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class Argon2HasherTest extends TestCase
9+
{
10+
public function testArgon2Hashing()
11+
{
12+
if (! defined('PASSWORD_ARGON2I')) {
13+
$this->markTestSkipped('PHP not compiled with argon2 hashing support.');
14+
}
15+
16+
$hasher = new Argon2Hasher();
17+
18+
$value = $hasher->make('password');
19+
$this->assertNotSame('password', $value);
20+
$this->assertTrue($hasher->check('password', $value));
21+
$this->assertFalse($hasher->needsRehash($value));
22+
$this->assertTrue($hasher->needsRehash($value, ['threads' => 1]));
23+
}
24+
}

0 commit comments

Comments
 (0)