tor-spider/tests/TorLocatorTest.php

58 lines
1.5 KiB
PHP

<?php
use Sikofitt\Tor\TorLocator;
/**
* Class TorLocatorTest
*/
class TorLocatorTest extends PHPUnit_Framework_TestCase {
private $torExecutableDir;
private $torExecutableFailureDir;
public function setUp() {
$this->torExecutableDir = __DIR__ . '/../tor-client/bin';
$this->torExecutableFailureDir = '/';
}
public function testLocatorSuccess()
{
$locator = new TorLocator($this->torExecutableDir);
$torBinary = $locator->getBinary();
$testBinary = new \SplFileInfo(__DIR__ . '/../tor-client/bin/tor');
$this->assertSame($testBinary->getRealPath(), $torBinary->getRealPath());
$this->assertSame(__DIR__ . '/../tor-client/bin', $torBinary->getPath());
$this->assertSame(__DIR__ . '/../tor-client/bin/tor', $torBinary->getPathname());
$this->assertTrue($torBinary->isExecutable(), true);
}
public function testLocatorAutoResolveSuccess()
{
$locator = new TorLocator();
$torBinary = $locator->getBinary();
$this->assertSame('/usr/bin/tor', $torBinary->getPathname());
}
public function testLocatorFailureWithCatch() {
try {
$locator = new TorLocator($this->torExecutableFailureDir);
$torBinary = $locator->getBinary();
} catch(\Exception $e) {
$this->assertSame('Couldn\'t find the tor binary.', $e->getMessage());
}
}
/**
* @expectedException \Exception
*/
public function testLocatorFailure()
{
$locator = new TorLocator($this->torExecutableFailureDir);
$torBinary = $locator->getBinary();
}
}