test fixes

This commit is contained in:
Robin Appelman 2025-10-25 23:00:02 +02:00
commit 824593c5ac
6 changed files with 27 additions and 23 deletions

View file

@ -27,7 +27,7 @@ use Icewind\SMB\Options;
use Icewind\SMB\System; use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider; use Icewind\SMB\TimeZoneProvider;
abstract class AbstractShareTest extends TestCase { abstract class AbstractShareTestBase extends TestCase {
/** /**
* @var \Icewind\SMB\IServer $server * @var \Icewind\SMB\IServer $server
*/ */

View file

@ -15,7 +15,7 @@ use Icewind\SMB\Options;
use Icewind\SMB\System; use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider; use Icewind\SMB\TimeZoneProvider;
class NativeShareTest extends AbstractShareTest { class NativeShareTest extends AbstractShareTestBase {
public function getServerClass(): string { public function getServerClass(): string {
$this->requireBackendEnv('libsmbclient'); $this->requireBackendEnv('libsmbclient');
if (!function_exists('smbclient_state_new')) { if (!function_exists('smbclient_state_new')) {

View file

@ -12,7 +12,7 @@ use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\Exception;
use Icewind\SMB\Exception\RevisionMismatchException; use Icewind\SMB\Exception\RevisionMismatchException;
use Icewind\SMB\INotifyHandler; use Icewind\SMB\INotifyHandler;
use Icewind\SMB\IShare; use Icewind\SMB\ISystem;
use Icewind\SMB\Options; use Icewind\SMB\Options;
use Icewind\SMB\System; use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider; use Icewind\SMB\TimeZoneProvider;
@ -199,8 +199,7 @@ class NotifyHandlerTest extends TestCase {
public function testNoStdBuf(): void { public function testNoStdBuf(): void {
$this->requireBackendEnv('smbclient'); $this->requireBackendEnv('smbclient');
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json')); $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$system = $this->getMockBuilder(System::class) $system = $this->getMockBuilder(ISystem::class)
->onlyMethods(['getStdBufPath'])
->getMock(); ->getMock();
$system->method('getStdBufPath') $system->method('getStdBufPath')
->willReturn(null); ->willReturn(null);

View file

@ -9,9 +9,9 @@ namespace Icewind\SMB\Test;
use Icewind\SMB\AnonymousAuth; use Icewind\SMB\AnonymousAuth;
use Icewind\SMB\Exception\DependencyException; use Icewind\SMB\Exception\DependencyException;
use Icewind\SMB\IAuth; use Icewind\SMB\IAuth;
use Icewind\SMB\ISystem;
use Icewind\SMB\Native\NativeServer; use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\ServerFactory; use Icewind\SMB\ServerFactory;
use Icewind\SMB\System;
use Icewind\SMB\Wrapped\Server; use Icewind\SMB\Wrapped\Server;
class ServerFactoryTest extends TestCase { class ServerFactoryTest extends TestCase {
@ -25,13 +25,14 @@ class ServerFactoryTest extends TestCase {
} }
public function testSmbClient() { public function testSmbClient() {
$this->requireBackendEnv('smbclient'); $system = $this->getMockBuilder(ISystem::class)
$system = $this->getMockBuilder(System::class)
->onlyMethods(['libSmbclientAvailable'])
->getMock(); ->getMock();
$system->expects($this->any()) $system->expects($this->any())
->method('libSmbclientAvailable') ->method('libSmbclientAvailable')
->willReturn(false); ->willReturn(false);
$system->expects($this->any())
->method('getSmbclientPath')
->willReturn("/usr/bin/smbclient");
$factory = new ServerFactory(null, $system); $factory = new ServerFactory(null, $system);
$this->assertInstanceOf(Server::class, $factory->createServer('localhost', $this->credentials)); $this->assertInstanceOf(Server::class, $factory->createServer('localhost', $this->credentials));
} }
@ -41,15 +42,19 @@ class ServerFactoryTest extends TestCase {
if (!function_exists('smbclient_state_new')) { if (!function_exists('smbclient_state_new')) {
$this->markTestSkipped('libsmbclient php extension not installed'); $this->markTestSkipped('libsmbclient php extension not installed');
} }
$factory = new ServerFactory(); $system = $this->getMockBuilder(ISystem::class)
->getMock();
$system->expects($this->any())
->method('libSmbclientAvailable')
->willReturn(true);
$factory = new ServerFactory(null, $system);
$this->assertInstanceOf(NativeServer::class, $factory->createServer('localhost', $this->credentials)); $this->assertInstanceOf(NativeServer::class, $factory->createServer('localhost', $this->credentials));
} }
public function testNoBackend() { public function testNoBackend() {
$this->expectException(DependencyException::class); $this->expectException(DependencyException::class);
$this->requireBackendEnv('smbclient'); $this->requireBackendEnv('smbclient');
$system = $this->getMockBuilder(System::class) $system = $this->getMockBuilder(ISystem::class)
->setMethods(['libSmbclientAvailable', 'getSmbclientPath'])
->getMock(); ->getMock();
$system->expects($this->any()) $system->expects($this->any())
->method('libSmbclientAvailable') ->method('libSmbclientAvailable')

View file

@ -14,7 +14,7 @@ use Icewind\SMB\System;
use Icewind\SMB\TimeZoneProvider; use Icewind\SMB\TimeZoneProvider;
use Icewind\SMB\Wrapped\Server as NormalServer; use Icewind\SMB\Wrapped\Server as NormalServer;
class ShareTest extends AbstractShareTest { class ShareTest extends AbstractShareTestBase {
public function getServerClass(): string { public function getServerClass(): string {
$this->requireBackendEnv('smbclient'); $this->requireBackendEnv('smbclient');
return NormalServer::class; return NormalServer::class;

View file

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
- SPDX-FileCopyrightText: 2012 Robin Appelman <robin@icewind.nl> - SPDX-FileCopyrightText: 2012 Robin Appelman <robin@icewind.nl>
- SPDX-License-Identifier: MIT - SPDX-License-Identifier: MIT
--> -->
<phpunit bootstrap="bootstrap.php"> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuite name='SMB'> <coverage processUncoveredFiles="true">
<directory suffix='.php'>./</directory> <include>
</testsuite> <directory suffix=".php">../src</directory>
<filter> </include>
<whitelist processUncoveredFilesFromWhitelist="true"> </coverage>
<directory suffix=".php">../src</directory> <testsuite name="SMB">
</whitelist> <directory suffix=".php">./</directory>
</filter> </testsuite>
</phpunit> </phpunit>