more configurability for library users

- Make TimeZoneProvider and System overridable
- Add system for passing additional options
- make timeout configurable
This commit is contained in:
Robin Appelman 2018-07-12 16:38:25 +02:00
commit 2f261f868d
20 changed files with 303 additions and 107 deletions

View file

@ -9,6 +9,7 @@ namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Options;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
@ -27,7 +28,8 @@ class NativeShareTest extends AbstractShareTest {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {

View file

@ -9,6 +9,7 @@ namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Options;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
@ -44,7 +45,8 @@ class NativeStreamTest extends TestCase {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {

View file

@ -12,6 +12,7 @@ use Icewind\SMB\Change;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IShare;
use Icewind\SMB\Options;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server;
@ -35,7 +36,8 @@ class NotifyHandlerTest extends TestCase {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
}

View file

@ -24,26 +24,11 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
array('RAH', IFileInfo::MODE_READONLY | IFileInfo::MODE_ARCHIVE | IFileInfo::MODE_HIDDEN)
);
}
/**
* @param string $timeZone
* @return \Icewind\SMB\TimeZoneProvider
*/
private function getTimeZoneProvider($timeZone) {
$mock = $this->getMockBuilder('\Icewind\SMB\TimeZoneProvider')
->disableOriginalConstructor()
->getMock();
$mock->expects($this->any())
->method('get')
->will($this->returnValue($timeZone));
return $mock;
}
/**
* @dataProvider modeProvider
*/
public function testParseMode($string, $mode) {
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('UTC'));
$parser = new \Icewind\SMB\Wrapped\Parser('UTC');
$this->assertEquals($mode, $parser->parseMode($string), 'Failed parsing ' . $string);
}
@ -104,7 +89,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
* @dataProvider statProvider
*/
public function testStat($output, $stat) {
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('UTC'));
$parser = new \Icewind\SMB\Wrapped\Parser('UTC');
$this->assertEquals($stat, $parser->parseStat($output));
}
@ -130,7 +115,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase {
* @dataProvider dirProvider
*/
public function testDir($output, $dir) {
$parser = new \Icewind\SMB\Wrapped\Parser($this->getTimeZoneProvider('CEST'));
$parser = new \Icewind\SMB\Wrapped\Parser('CEST');
$this->assertEquals($dir, $parser->parseDir($output, ''));
}
}

View file

@ -8,6 +8,7 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Options;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server;
@ -31,7 +32,8 @@ class ServerTest extends TestCase {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
}
@ -58,7 +60,8 @@ class ServerTest extends TestCase {
uniqid()
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$server->listShares();
}
@ -75,7 +78,8 @@ class ServerTest extends TestCase {
uniqid()
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$server->listShares();
}
@ -92,7 +96,8 @@ class ServerTest extends TestCase {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$server->listShares();
}
@ -110,7 +115,8 @@ class ServerTest extends TestCase {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$server->listShares();
}

View file

@ -8,6 +8,7 @@
namespace Icewind\SMB\Test;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Options;
use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server as NormalServer;
@ -24,7 +25,8 @@ class ShareTest extends AbstractShareTest {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$this->share = $this->server->getShare($this->config->share);
if ($this->config->root) {
@ -49,7 +51,8 @@ class ShareTest extends AbstractShareTest {
$this->config->password
),
new System(),
new TimeZoneProvider($this->config->host, new System())
new TimeZoneProvider(new System()),
new Options()
);
$share = $this->server->getShare($this->config->share);
$share->dir($this->root);