diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..7e49c60 --- /dev/null +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..81bd02a --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,20 @@ + + + + + + ./tests/Bijective/ + + + \ No newline at end of file diff --git a/tests/Bijective/Tests/BijectiveTranslatorTest.php b/tests/Bijective/Tests/BijectiveTranslatorTest.php new file mode 100644 index 0000000..b43a6f3 --- /dev/null +++ b/tests/Bijective/Tests/BijectiveTranslatorTest.php @@ -0,0 +1,73 @@ + + */ +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)) + ); + } +}