check if we can find smbclient in path

This commit is contained in:
Robin Appelman 2016-12-01 13:04:56 +01:00
commit 7ddcd96e47
3 changed files with 24 additions and 3 deletions

View file

@ -153,7 +153,7 @@ class Server {
* @return \Icewind\SMB\IShare
*/
public function getShare($name) {
return new Share($this, $name);
return new Share($this, $name, $this->system);
}
/**

View file

@ -43,17 +43,22 @@ class Share extends AbstractShare {
/**
* @param Server $server
* @param string $name
* @param System $system
*/
public function __construct($server, $name) {
public function __construct($server, $name, System $system = null) {
parent::__construct();
$this->server = $server;
$this->name = $name;
$this->system = new System();
$this->system = (!is_null($system)) ? $system : new System();
$this->parser = new Parser(new TimeZoneProvider($this->server->getHost(), $this->system));
}
protected function getConnection() {
$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
$smbClientPath = $this->system->getSmbclientPath();
if (!$smbClientPath) {
throw new DependencyException('Can\'t find smbclient binary in path');
}
$command = sprintf('%s%s %s --authentication-file=%s %s',
$this->system->hasStdBuf() ? 'stdbuf -o0 ' : '',
$this->system->getSmbclientPath(),

View file

@ -33,4 +33,20 @@ class Share extends AbstractShare {
$share = $this->server->getShare($this->config->share);
$share->dir($this->root);
}
/**
* @expectedException \Icewind\SMB\Exception\DependencyException
*/
public function testNoSmbclient() {
$system = $this->getMockBuilder('\Icewind\SMB\System')
->setMethods(['getSmbclientPath'])
->getMock();
$share = new \Icewind\SMB\Share($this->server, 'dummy', $system);
$system->expects($this->any())
->method('getSmbclientPath')
->will($this->returnValue(''));
$share->mkdir('');
}
}