mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
update tests to new phpunit
This commit is contained in:
parent
743a7bf353
commit
58f6df3807
11 changed files with 59 additions and 101 deletions
|
|
@ -7,8 +7,12 @@
|
|||
|
||||
namespace Icewind\SMB\Test;
|
||||
|
||||
use Icewind\SMB\Exception\AlreadyExistsException;
|
||||
use Icewind\SMB\Exception\FileInUseException;
|
||||
use Icewind\SMB\Exception\InvalidPathException;
|
||||
use Icewind\SMB\Exception\InvalidResourceException;
|
||||
use Icewind\SMB\Exception\InvalidTypeException;
|
||||
use Icewind\SMB\Exception\NotEmptyException;
|
||||
use Icewind\SMB\Exception\NotFoundException;
|
||||
use Icewind\SMB\FileInfo;
|
||||
use Icewind\SMB\IFileInfo;
|
||||
|
|
@ -32,7 +36,7 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
protected $config;
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown(): void {
|
||||
try {
|
||||
if ($this->share) {
|
||||
try {
|
||||
|
|
@ -142,9 +146,9 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testMkdirInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->mkdir($this->root . '/' . $name);
|
||||
$dirs = $this->share->dir($this->root);
|
||||
$this->assertCount(1, $dirs);
|
||||
|
|
@ -191,9 +195,9 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testPutInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$tmpFile = $this->getTextFile('foo');
|
||||
|
||||
try {
|
||||
|
|
@ -237,10 +241,8 @@ abstract class AbstractShareTest extends TestCase {
|
|||
unlink($targetFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidResourceException
|
||||
*/
|
||||
public function testGetInvalidTarget() {
|
||||
$this->expectException(InvalidResourceException::class);
|
||||
$name = 'test.txt';
|
||||
$text = 'dummy';
|
||||
$tmpFile = $this->getTextFile($text);
|
||||
|
|
@ -273,78 +275,60 @@ abstract class AbstractShareTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testCreateFolderInNonExistingFolder() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->mkdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRemoveFolderInNonExistingFolder() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->rmdir($this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRemoveNonExistingFolder() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->rmdir($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\AlreadyExistsException
|
||||
*/
|
||||
public function testCreateExistingFolder() {
|
||||
$this->expectException(AlreadyExistsException::class);
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->rmdir($this->root . '/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testCreateFileExistingFolder() {
|
||||
$this->expectException(InvalidTypeException::class);
|
||||
$this->share->mkdir($this->root . '/bar');
|
||||
$this->share->put($this->getTextFile(), $this->root . '/bar');
|
||||
$this->share->rmdir($this->root . '/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testCreateFileInNonExistingFolder() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testTestRemoveNonExistingFile() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->del($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testDownloadInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->get($name, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testDownloadNonExistingFile() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->get($this->root . '/foo', '/dev/null');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testDownloadFolder() {
|
||||
$this->expectException(InvalidTypeException::class);
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
$this->share->get($this->root . '/foobar', '/dev/null');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
|
|
@ -352,25 +336,21 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testDelInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->del($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
|
||||
*/
|
||||
public function testRmdirFile() {
|
||||
$this->expectException(InvalidTypeException::class);
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foobar');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
$this->share->del($this->root . '/foobar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotEmptyException
|
||||
*/
|
||||
public function testRmdirNotEmpty() {
|
||||
$this->expectException(NotEmptyException::class);
|
||||
$this->share->mkdir($this->root . '/foobar');
|
||||
$this->share->put($this->getTextFile(), $this->root . '/foobar/asd');
|
||||
$this->share->rmdir($this->root . '/foobar');
|
||||
|
|
@ -378,45 +358,37 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testRmDirInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->rmdir($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testDirNonExisting() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->dir('/foobar/asd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRmDirNonExisting() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->rmdir('/foobar/asd');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRenameNonExisting() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->rename('/foobar/asd', '/foobar/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testRenameInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->rename($name, $name . '_');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testRenameTargetNonExisting() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$txt = $this->getTextFile();
|
||||
$this->share->put($txt, $this->root . '/foo.txt');
|
||||
unlink($txt);
|
||||
|
|
@ -448,9 +420,9 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testReadStreamInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->read($name);
|
||||
}
|
||||
|
||||
|
|
@ -488,9 +460,9 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testWriteStreamInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$fh = $this->share->write($this->root . '/' . $name);
|
||||
fwrite($fh, 'foo');
|
||||
fclose($fh);
|
||||
|
|
@ -525,9 +497,9 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testDirInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->dir($name);
|
||||
}
|
||||
|
||||
|
|
@ -547,16 +519,14 @@ abstract class AbstractShareTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider invalidPathProvider
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidPathException
|
||||
*/
|
||||
public function testStatInvalidPath($name) {
|
||||
$this->expectException(InvalidPathException::class);
|
||||
$this->share->stat($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\NotFoundException
|
||||
*/
|
||||
public function testStatNonExisting() {
|
||||
$this->expectException(NotFoundException::class);
|
||||
$this->share->stat($this->root . '/fo.txt');
|
||||
}
|
||||
|
||||
|
|
@ -687,10 +657,8 @@ abstract class AbstractShareTest extends TestCase {
|
|||
$this->assertInstanceOf('\Icewind\SMB\IFileInfo', $info);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\FileInUseException
|
||||
*/
|
||||
public function testMoveIntoSelf() {
|
||||
$this->expectException(FileInUseException::class);
|
||||
$this->share->mkdir($this->root . '/folder');
|
||||
$this->share->rename($this->root . '/folder', $this->root . '/folder/subfolder');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Icewind\SMB\System;
|
|||
use Icewind\SMB\TimeZoneProvider;
|
||||
|
||||
class NativeShareTest extends AbstractShareTest {
|
||||
public function setUp() {
|
||||
public function setUp(): void {
|
||||
$this->requireBackendEnv('libsmbclient');
|
||||
if (!function_exists('smbclient_state_new')) {
|
||||
$this->markTestSkipped('libsmbclient php extension not installed');
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class NativeStreamTest extends TestCase {
|
|||
|
||||
protected $config;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp(): void {
|
||||
$this->requireBackendEnv('libsmbclient');
|
||||
if (!function_exists('smbclient_state_new')) {
|
||||
$this->markTestSkipped('libsmbclient php extension not installed');
|
||||
|
|
@ -137,7 +137,7 @@ class NativeStreamTest extends TestCase {
|
|||
$this->assertFalse(stream_set_blocking($fh, false));
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown(): void {
|
||||
if ($this->share) {
|
||||
$this->cleanDir($this->root);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class NotifyHandlerTest extends TestCase {
|
|||
|
||||
private $config;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp(): void {
|
||||
$this->requireBackendEnv('smbclient');
|
||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||
$this->server = new Server(
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
namespace Icewind\SMB\Test;
|
||||
|
||||
use Icewind\SMB\AnonymousAuth;
|
||||
use Icewind\SMB\Exception\DependencyException;
|
||||
use Icewind\SMB\IAuth;
|
||||
use Icewind\SMB\Native\NativeServer;
|
||||
use Icewind\SMB\ServerFactory;
|
||||
|
|
@ -32,7 +33,7 @@ class ServerFactoryTest extends TestCase {
|
|||
/** @var IAuth */
|
||||
private $credentials;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->credentials = new AnonymousAuth();
|
||||
|
|
@ -59,10 +60,8 @@ class ServerFactoryTest extends TestCase {
|
|||
$this->assertInstanceOf(NativeServer::class, $factory->createServer('localhost', $this->credentials));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\DependencyException
|
||||
*/
|
||||
public function testNoBackend() {
|
||||
$this->expectException(DependencyException::class);
|
||||
$this->requireBackendEnv('smbclient');
|
||||
$system = $this->getMockBuilder(System::class)
|
||||
->setMethods(['libSmbclientAvailable', 'getSmbclientPath'])
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
namespace Icewind\SMB\Test;
|
||||
|
||||
use Icewind\SMB\BasicAuth;
|
||||
use Icewind\SMB\Exception\AuthenticationException;
|
||||
use Icewind\SMB\Exception\InvalidHostException;
|
||||
use Icewind\SMB\IShare;
|
||||
use Icewind\SMB\Options;
|
||||
use Icewind\SMB\System;
|
||||
|
|
@ -22,7 +24,7 @@ class ServerTest extends TestCase {
|
|||
|
||||
private $config;
|
||||
|
||||
public function setUp() {
|
||||
public function setUp(): void {
|
||||
$this->requireBackendEnv('smbclient');
|
||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||
$this->server = new Server(
|
||||
|
|
@ -47,10 +49,8 @@ class ServerTest extends TestCase {
|
|||
$this->assertContains($this->config->share, $names);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\AuthenticationException
|
||||
*/
|
||||
public function testWrongUserName() {
|
||||
$this->expectException(AuthenticationException::class);
|
||||
$this->markTestSkipped('This fails for no reason on travis');
|
||||
$server = new Server(
|
||||
$this->config->host,
|
||||
|
|
@ -66,10 +66,8 @@ class ServerTest extends TestCase {
|
|||
$server->listShares();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\AuthenticationException
|
||||
*/
|
||||
public function testWrongPassword() {
|
||||
$this->expectException(AuthenticationException::class);
|
||||
$server = new Server(
|
||||
$this->config->host,
|
||||
new BasicAuth(
|
||||
|
|
@ -84,10 +82,8 @@ class ServerTest extends TestCase {
|
|||
$server->listShares();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function testWrongHost() {
|
||||
$this->expectException(InvalidHostException::class);
|
||||
$server = new Server(
|
||||
uniqid(),
|
||||
new BasicAuth(
|
||||
|
|
@ -102,11 +98,8 @@ class ServerTest extends TestCase {
|
|||
$server->listShares();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function testHostEscape() {
|
||||
$this->expectException(InvalidHostException::class);
|
||||
$server = new Server(
|
||||
$this->config->host . ';asd',
|
||||
new BasicAuth(
|
||||
|
|
|
|||
|
|
@ -8,13 +8,15 @@
|
|||
namespace Icewind\SMB\Test;
|
||||
|
||||
use Icewind\SMB\BasicAuth;
|
||||
use Icewind\SMB\Exception\ConnectException;
|
||||
use Icewind\SMB\Exception\DependencyException;
|
||||
use Icewind\SMB\Options;
|
||||
use Icewind\SMB\System;
|
||||
use Icewind\SMB\TimeZoneProvider;
|
||||
use Icewind\SMB\Wrapped\Server as NormalServer;
|
||||
|
||||
class ShareTest extends AbstractShareTest {
|
||||
public function setUp() {
|
||||
public function setUp(): void {
|
||||
$this->requireBackendEnv('smbclient');
|
||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||
$this->server = new NormalServer(
|
||||
|
|
@ -37,17 +39,13 @@ class ShareTest extends AbstractShareTest {
|
|||
$this->share->mkdir($this->root);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\DependencyException
|
||||
*/
|
||||
public function testAppendStream() {
|
||||
$this->expectException(DependencyException::class);
|
||||
$this->share->append($this->root . '/foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Icewind\SMB\Exception\ConnectException
|
||||
*/
|
||||
public function testHostEscape() {
|
||||
$this->expectException(ConnectException::class);
|
||||
$this->requireBackendEnv('smbclient');
|
||||
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
|
||||
$this->server = new NormalServer(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class TimeZoneProviderTest extends TestCase {
|
|||
/** @var TimeZoneProvider */
|
||||
private $provider;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->system = $this->createMock(ISystem::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue