-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement \ArrayAccess, \Countable, \IteratorAggregate.
Add PHPUnit. Add tests for Helper. Improve README.md. Change the minimum version of PHP on 5.5.
- Loading branch information
Showing
5 changed files
with
259 additions
and
16 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
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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="vendor/autoload.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="All tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</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,122 @@ | ||
<?php | ||
|
||
use SlimSession\Helper; | ||
|
||
session_start(); | ||
|
||
class HelperTest extends PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
$_SESSION = []; | ||
} | ||
|
||
public function testExists() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = $data = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$this->assertTrue($helper->exists('a')); | ||
$this->assertFalse($helper->exists('aa')); | ||
|
||
$this->assertTrue(isset($helper->b)); | ||
$this->assertFalse(isset($helper->bb)); | ||
|
||
$this->assertTrue(isset($helper['c'])); | ||
$this->assertFalse(isset($helper['cc'])); | ||
} | ||
|
||
public function testSet() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$helper->set('a', 'A'); | ||
$this->assertSame(['a' => 'A'], $_SESSION); | ||
|
||
$helper->b = 'B'; | ||
$this->assertSame(['a' => 'A', 'b' => 'B'], $_SESSION); | ||
|
||
$helper['c'] = 'C'; | ||
$this->assertSame(['a' => 'A', 'b' => 'B', 'c' => 'C'], $_SESSION); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$this->assertSame('A', $helper->get('a')); | ||
$this->assertNull($helper->get('aa')); | ||
$this->assertSame('AAA', $helper->get('aaa', 'AAA')); | ||
|
||
$this->assertSame('B', $helper->b); | ||
$this->assertNull($helper->bb); | ||
|
||
$this->assertSame('C', $helper['c']); | ||
$this->assertNull($helper['cc']); | ||
} | ||
|
||
public function testDelete() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = $data = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$helper->delete('A'); | ||
$this->assertSame($data, $_SESSION); | ||
|
||
$helper->delete('a'); | ||
unset($data['a']); | ||
$this->assertSame($data, $_SESSION); | ||
|
||
unset($helper->b, $data['b']); | ||
$this->assertSame($data, $_SESSION); | ||
|
||
unset($helper['c'], $data['c']); | ||
$this->assertSame($data, $_SESSION); | ||
} | ||
|
||
public function testClear() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$helper->clear(); | ||
$this->assertEmpty($_SESSION); | ||
} | ||
|
||
public function testId() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$this->assertSame(session_id(), $helper::id()); | ||
$this->markTestIncomplete('Please implement check for "::id(true)"'); | ||
} | ||
|
||
public function testDestroy() | ||
{ | ||
$this->markTestIncomplete('Please implement check for "::destroy"'); | ||
} | ||
|
||
public function testCount() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$this->assertCount($helper->count(), $_SESSION); | ||
} | ||
|
||
public function testIterator() | ||
{ | ||
$helper = new Helper(); | ||
|
||
$_SESSION = ['a' => 'A', 'b' => 'B', 'c' => 'C']; | ||
|
||
$this->assertInstanceOf(Iterator::class, $helper->getIterator()); | ||
$this->assertSame($_SESSION, iterator_to_array($helper->getIterator())); | ||
} | ||
} |