mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +02:00
server factory tests
This commit is contained in:
parent
fc9963f738
commit
fc9f0bd408
4 changed files with 93 additions and 2 deletions
|
|
@ -54,4 +54,11 @@ interface ISystem {
|
||||||
* @return string|bool
|
* @return string|bool
|
||||||
*/
|
*/
|
||||||
public function getStdBufPath();
|
public function getStdBufPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the smbclient php extension is enabled
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function libSmbclientAvailable();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,6 @@ class NativeServer extends AbstractServer {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function available(ISystem $system) {
|
public static function available(ISystem $system) {
|
||||||
return function_exists('smbclient_state_new');
|
return $system->libSmbclientAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,11 @@ class System implements ISystem {
|
||||||
return $this->getBinaryPath('stdbuf');
|
return $this->getBinaryPath('stdbuf');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBinaryPath($binary) {
|
public function libSmbclientAvailable() {
|
||||||
|
return function_exists('smbclient_state_new');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getBinaryPath($binary) {
|
||||||
if (!isset($this->paths[$binary])) {
|
if (!isset($this->paths[$binary])) {
|
||||||
$result = null;
|
$result = null;
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
|
||||||
80
tests/ServerFactoryTest.php
Normal file
80
tests/ServerFactoryTest.php
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
|
||||||
|
*
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Icewind\SMB\Test;
|
||||||
|
|
||||||
|
|
||||||
|
use Icewind\SMB\AnonymousAuth;
|
||||||
|
use Icewind\SMB\IAuth;
|
||||||
|
use Icewind\SMB\Native\NativeServer;
|
||||||
|
use Icewind\SMB\ServerFactory;
|
||||||
|
use Icewind\SMB\System;
|
||||||
|
use Icewind\SMB\Wrapped\Server;
|
||||||
|
|
||||||
|
class ServerFactoryTest extends TestCase {
|
||||||
|
/** @var IAuth */
|
||||||
|
private $credentials;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->credentials = new AnonymousAuth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSmbClient() {
|
||||||
|
$this->requireBackendEnv('smbclient');
|
||||||
|
$system = $this->getMockBuilder(System::class)
|
||||||
|
->setMethods(['libSmbclientAvailable'])
|
||||||
|
->getMock();
|
||||||
|
$system->expects($this->any())
|
||||||
|
->method('libSmbclientAvailable')
|
||||||
|
->willReturn(false);
|
||||||
|
$factory = new ServerFactory(null, $system);
|
||||||
|
$this->assertInstanceOf(Server::class, $factory->createServer('localhost', $this->credentials));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLibSmbClient() {
|
||||||
|
$this->requireBackendEnv('libsmbclient');
|
||||||
|
if (!function_exists('smbclient_state_new')) {
|
||||||
|
$this->markTestSkipped('libsmbclient php extension not installed');
|
||||||
|
}
|
||||||
|
$factory = new ServerFactory();
|
||||||
|
$this->assertInstanceOf(NativeServer::class, $factory->createServer('localhost', $this->credentials));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Icewind\SMB\Exception\DependencyException
|
||||||
|
*/
|
||||||
|
public function testNoBackend() {
|
||||||
|
$this->requireBackendEnv('smbclient');
|
||||||
|
$system = $this->getMockBuilder(System::class)
|
||||||
|
->setMethods(['libSmbclientAvailable', 'getSmbclientPath'])
|
||||||
|
->getMock();
|
||||||
|
$system->expects($this->any())
|
||||||
|
->method('libSmbclientAvailable')
|
||||||
|
->willReturn(false);
|
||||||
|
$system->expects($this->any())
|
||||||
|
->method('getSmbclientPath')
|
||||||
|
->willReturn(false);
|
||||||
|
$factory = new ServerFactory(null, $system);
|
||||||
|
$factory->createServer('localhost', $this->credentials);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue