From e7df2a7c20ae97dd25e57b3e7d70836ea68e7d42 Mon Sep 17 00:00:00 2001 From: Brian Freytag Date: Wed, 19 Nov 2014 11:52:32 -0500 Subject: [PATCH] Add unit tests --- .travis.yml | 15 ++++ phpunit.xml.dist | 20 +++++ .../Tests/BijectiveTranslatorTest.php | 73 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .travis.yml create mode 100644 phpunit.xml.dist create mode 100644 tests/Bijective/Tests/BijectiveTranslatorTest.php 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)) + ); + } +}