Skip to content

Commit

Permalink
Add unit tests for internal APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsLeenheer committed Dec 8, 2015
1 parent 3c19ff7 commit 562eb82
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/unit/AnalyserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace WhichBrowserTest;

use PHPUnit_Framework_TestCase;
use WhichBrowser\Analyser;
use WhichBrowser\Model\Main;

/**
* @covers WhichBrowser\Parser
*/
class AnalyserTest extends PHPUnit_Framework_TestCase
{
public function testCreatingAnalyserGetData()
{
$analyser = new Analyser("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)");

$this->assertTrue($analyser instanceof \WhichBrowser\Analyser);

$analyser->analyse();

$data = $analyser->getData();

$this->assertTrue($data instanceof \WhichBrowser\Model\Main);
}

public function testCreatingAnalyserSetData()
{
$analyser = new Analyser("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)");

$this->assertTrue($analyser instanceof \WhichBrowser\Analyser);

$input = new Main();

$this->assertTrue($input instanceof \WhichBrowser\Model\Main);

$analyser->setData($input);

$analyser->analyse();

$output = $analyser->getData();

$this->assertTrue($output instanceof \WhichBrowser\Model\Main);
}
}
44 changes: 44 additions & 0 deletions tests/unit/ParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace WhichBrowserTest;

use PHPUnit_Framework_TestCase;
use WhichBrowser\Parser;

/**
* @covers WhichBrowser\Parser
*/
class ParserTest extends PHPUnit_Framework_TestCase
{
public function testCreatingParserWithString()
{
$parser = new Parser("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)");

$this->assertTrue($parser instanceof \WhichBrowser\Parser);

$this->assertTrue($parser->isBrowser('Internet Explorer', '=', '6.0'));
}

public function testCreatingParserWithHeaders()
{
$parser = new Parser([
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)'
]);

$this->assertTrue($parser instanceof \WhichBrowser\Parser);

$this->assertTrue($parser->isBrowser('Internet Explorer', '=', '6.0'));
}

public function testCreatingParserWithOptions()
{
$parser = new Parser([
'headers' => [
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; InfoPath.1)'
]
]);

$this->assertTrue($parser instanceof \WhichBrowser\Parser);

$this->assertTrue($parser->isBrowser('Internet Explorer', '=', '6.0'));
}
}

0 comments on commit 562eb82

Please sign in to comment.