Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Freytag committed Nov 19, 2014
1 parent e050c50 commit e7df2a7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .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
20 changes: 20 additions & 0 deletions phpunit.xml.dist
@@ -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>
73 changes: 73 additions & 0 deletions tests/Bijective/Tests/BijectiveTranslatorTest.php
@@ -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))
);
}
}

0 comments on commit e7df2a7

Please sign in to comment.