Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Freytag
committed
Nov 19, 2014
1 parent
e050c50
commit e7df2a7
Showing
3 changed files
with
108 additions
and
0 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,15 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3.3 | ||
- 5.3 | ||
- 5.4 | ||
- 5.5 | ||
- hhvm | ||
|
||
before_script: | ||
- composer self-update | ||
- composer update --prefer-source --dev | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit | ||
bootstrap="./vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
verbose="true" | ||
stopOnFailure="false" | ||
processIsolation="false" | ||
backupGlobals="false" | ||
syntaxCheck="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Bijective Test Suite"> | ||
<directory>./tests/Bijective/</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Bijective\Tests; | ||
|
||
use Bijective\BijectiveTranslator; | ||
|
||
/** | ||
* @coversDefaultClass Bijective\BijectiveTranslator | ||
* | ||
* @package Bijective | ||
* | ||
* @author Brian Freytag <brian@idltg.in> | ||
*/ | ||
class BijectiveTranslatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var BijectiveTranslator */ | ||
private $bijective; | ||
|
||
public function setUp() | ||
{ | ||
$this->bijective = new BijectiveTranslator(); | ||
} | ||
|
||
public function testEncodeReturnsString() | ||
{ | ||
$this->assertInternalType('string', $this->bijective->encode("123")); | ||
$this->assertInternalType('string', $this->bijective->encode(1234)); | ||
$this->assertInternalType('string', $this->bijective->encode('432')); | ||
} | ||
|
||
/** | ||
* @expectedException \Bijective\Exception\BijectiveException | ||
*/ | ||
public function testEncodeThrowsExceptionOnInvalidTypes() | ||
{ | ||
$this->bijective->encode(array()); | ||
$this->bijective->encode("string"); | ||
$this->bijective->encode(new \stdClass()); | ||
} | ||
|
||
public function testDecodeReturnsInteger() | ||
{ | ||
$this->assertInternalType('integer', $this->bijective->decode("asfdw")); | ||
$this->assertInternalType('integer', $this->bijective->decode("jiadoasdf")); | ||
$this->assertInternalType('integer', $this->bijective->decode("ADSjf3asdf")); | ||
} | ||
|
||
/** | ||
* @expectedException \Bijective\Exception\BijectiveException | ||
*/ | ||
public function testDecodesThrowsExceptionOnInvalidTypes() | ||
{ | ||
$this->bijective->decode(1234); | ||
$this->bijective->decode(array()); | ||
$this->bijective->decode(new \stdClass()); | ||
} | ||
|
||
public function testEncodeDecodeReturnExpectedValues() | ||
{ | ||
$this->assertEquals('ct', $this->bijective->encode(123)); | ||
$this->assertEquals(123, $this->bijective->decode('ct')); | ||
|
||
$this->assertEquals( | ||
'fdspadsf', | ||
$this->bijective->encode($this->bijective->decode('fdspadsf')) | ||
); | ||
|
||
$this->assertEquals( | ||
43489, | ||
$this->bijective->decode($this->bijective->encode(43489)) | ||
); | ||
} | ||
} |