-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from byjg/issue-4
Issue 4 - Convert issues
- Loading branch information
Showing
7 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: php | ||
|
||
php: | ||
- "7.2" | ||
- "7.1" | ||
- "7.0" | ||
- "5.6" | ||
|
||
install: | ||
- composer install | ||
|
||
script: | ||
- vendor/bin/phpunit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
To change this license header, choose License Headers in Project Properties. | ||
To change this template file, choose Tools | Templates | ||
and open the template in the editor. | ||
--> | ||
|
||
<!-- see http://www.phpunit.de/wiki/Documentation --> | ||
<phpunit bootstrap="./vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="false"> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>./src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
namespace ByJG\Session; | ||
|
||
class JwtSessionException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
use ByJG\Session\JwtSession; | ||
|
||
ob_start(); | ||
define("SETCOOKIE_FORTEST", "TESTCASE"); | ||
|
||
class JwtSessionTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var JwtSession | ||
*/ | ||
protected $object; | ||
|
||
const SESSION_ID = "sessionid"; | ||
|
||
protected function setUp() | ||
{ | ||
$this->object = new JwtSession("example.com", "secretKey"); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
header_remove(); | ||
$_COOKIE = []; | ||
$this->object = null; | ||
} | ||
|
||
|
||
public function testDestroy() | ||
{ | ||
$this->assertTrue($this->object->destroy(self::SESSION_ID)); | ||
} | ||
|
||
public function testGc() | ||
{ | ||
$this->assertTrue($this->object->gc(0)); | ||
} | ||
|
||
public function testClose() | ||
{ | ||
$this->assertTrue($this->object->close()); | ||
} | ||
|
||
public function dataProvider() | ||
{ | ||
$obj = new stdClass(); | ||
$obj->prop1 = "value1"; | ||
$obj->prop2 = "value2"; | ||
|
||
return | ||
[ | ||
[ | ||
[ | ||
"text" => "simple string" | ||
], | ||
"text|s:13:\"simple string\";" | ||
], | ||
[ | ||
[ | ||
"text" => "simple string", | ||
"text2" => "another string", | ||
"number" => 74 | ||
], | ||
"text|s:13:\"simple string\";text2|s:14:\"another string\";number|i:74;" | ||
], | ||
[ | ||
[ | ||
"text" => [ 1, 2, 3 ] | ||
], | ||
"text|a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}" | ||
], | ||
[ | ||
[ | ||
"text" => [ "a" => 1, "b" => 2, "c" => 3 ] | ||
], | ||
"text|a:3:{s:1:\"a\";i:1;s:1:\"b\";i:2;s:1:\"c\";i:3;}" | ||
], | ||
[ | ||
[ | ||
"text" => [ "a" => 1, "b" => 2, "c" => 3 ], | ||
"single" => 2000 | ||
], | ||
"text|a:3:{s:1:\"a\";i:1;s:1:\"b\";i:2;s:1:\"c\";i:3;}single|i:2000;" | ||
], | ||
[ | ||
[ | ||
"text" => $obj | ||
], | ||
"text|O:8:\"stdClass\":2:{s:5:\"prop1\";s:6:\"value1\";s:5:\"prop2\";s:6:\"value2\";}" | ||
], | ||
[ | ||
[ | ||
"text" => [ "a" => $obj ] | ||
], | ||
"text|a:1:{s:1:\"a\";O:8:\"stdClass\":2:{s:5:\"prop1\";s:6:\"value1\";s:5:\"prop2\";s:6:\"value2\";}}" | ||
], | ||
[ | ||
[ | ||
"text" => [ $obj ] | ||
], | ||
"text|a:1:{i:0;O:8:\"stdClass\":2:{s:5:\"prop1\";s:6:\"value1\";s:5:\"prop2\";s:6:\"value2\";}}" | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
* @param $input | ||
* @param $expected | ||
*/ | ||
public function testSerializeSessionData($input, $expected) | ||
{ | ||
$result = $this->object->serializeSessionData($input); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
* @param $expected | ||
* @param $input | ||
* @throws Exception | ||
*/ | ||
public function testUnserializeData($expected, $input) | ||
{ | ||
$result = $this->object->unSerializeSessionData($input); | ||
$this->assertEquals($expected, $result); | ||
} | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
* @param $object | ||
* @param $serialize | ||
*/ | ||
public function testReadWrite($object, $serialize) | ||
{ | ||
$this->object->write("SESSID", $serialize); | ||
$result = $this->object->read("SESSID"); | ||
$this->assertEquals($serialize, $result); | ||
} | ||
|
||
} |