Tests are now compliant with php-cs-fixer (CamelCase for method, phpdoc valid)

This commit is contained in:
2023-04-13 22:22:46 +02:00
parent b017700d0a
commit 273db5f183
51 changed files with 3926 additions and 3637 deletions

View File

@@ -1,26 +1,29 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD
*/
/**
* DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD
*/
namespace Domframework\Tests;
use Domframework\Jwt;
/** Test the Jwt.php file */
/**
* Test the Jwt.php file
*/
class JwtTest extends \PHPUnit_Framework_TestCase
{
public function test_createKey_1()
public function testCreateKey1()
{
$jwt = new Jwt();
$res = $jwt->createKey();
$this->assertSame(40, strlen($res));
}
public function test_sign_1()
public function testSign1()
{
$jwt = new Jwt();
$res = $this->invokeMethod(
@@ -36,7 +39,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_sign_2()
public function testSign2()
{
$jwt = new Jwt();
$res = $this->invokeMethod(
@@ -52,7 +55,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_sign_3()
public function testSign3()
{
$jwt = new Jwt();
$res = $this->invokeMethod(
@@ -68,10 +71,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_encode_1()
public function testEncode1()
{
$jwt = new Jwt();
$res = $jwt->encode(array ("payload" => "value"), "key to use", "HS384");
$res = $jwt->encode(["payload" => "value"], "key to use", "HS384");
$this->assertSame(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9." .
"eyJwYXlsb2FkIjoidmFsdWUifQ." .
@@ -80,7 +83,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_decode_1()
public function testDecode1()
{
$jwt = new Jwt();
$res = $jwt->decode(
@@ -89,10 +92,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
"key to use"
);
$this->assertSame((object)array ("payload" => "value"), $res);
$this->assertSame((object)["payload" => "value"], $res);
}
public function test_decode_2()
public function testDecode2()
{
$GLOBALS["hash_equals"] = false;
$jwt = new Jwt();
@@ -102,10 +105,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
"key to use"
);
$this->assertSame((object)array ("payload" => "value"), $res);
$this->assertSame((object)["payload" => "value"], $res);
}
public function test_decode_3()
public function testDecode3()
{
$jwt = new Jwt();
$this->expectException("Exception", "JWT with Empty algorithm");
@@ -117,7 +120,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_decode_4()
public function testDecode4()
{
$jwt = new Jwt();
$this->expectException("Exception", "JWT Payload not readable");
@@ -129,7 +132,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_decode_5()
public function testDecode5()
{
$jwt = new Jwt();
$this->expectException(
@@ -144,7 +147,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_decode_6()
public function testDecode6()
{
$jwt = new Jwt();
$this->expectException(
@@ -159,7 +162,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
);
}
public function test_decode_7()
public function testDecode7()
{
$jwt = new Jwt();
$this->expectException(
@@ -176,8 +179,9 @@ class JwtTest extends \PHPUnit_Framework_TestCase
///////////////////////////////
// ENCRYPT THE PAYLOAD //
///////////////////////////////
/** Check the length of the otken with cipher
*/
/**
* Check the length of the otken with cipher
*/
public function testEncrypt1()
{
$jwt = new Jwt();
@@ -191,8 +195,9 @@ class JwtTest extends \PHPUnit_Framework_TestCase
$this->assertSame(strlen($res), 156);
}
/** Check if the encrypt/decrypt process return the same result
*/
/**
* Check if the encrypt/decrypt process return the same result
*/
public function testEncrypyt2()
{
$jwt = new Jwt();
@@ -203,15 +208,16 @@ class JwtTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, $payload);
}
/** Check if the encrypted part is well unreadable
*/
/**
* Check if the encrypted part is well unreadable
*/
public function testEncrypt3()
{
$jwt = new Jwt();
$key = $jwt->createKey();
$payload = (object)["email" => "toto@example.com", "password" => "ToTo"];
$token = $jwt->encode($payload, $key, "HS256", "123456789012345678901234");
list ($header, $payload, $signature) = explode(".", $token);
list($header, $payload, $signature) = explode(".", $token);
$res = strpos(base64_decode($payload), "email");
$this->assertSame($res, false);
}