Skip to content

Commit 58f6df3

Browse files
committed
update tests to new phpunit
1 parent 743a7bf commit 58f6df3

11 files changed

+59
-101
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ composer.lock
44
.php_cs.cache
55
listen.php
66
test.php
7+
*.cache

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ dist: bionic
22
sudo: required
33
language: php
44
php:
5-
- 7.1
6-
- 7.2
75
- 7.3
86
- 7.4
7+
- 8.0
98

109
addons:
1110
apt:

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
}
1010
],
1111
"require" : {
12-
"php": ">=7.1",
13-
"icewind/streams": ">=0.2.0"
12+
"php": ">=7.3",
13+
"icewind/streams": ">=0.7.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "^7.0",
17-
"friendsofphp/php-cs-fixer": "^2.13"
16+
"phpunit/phpunit": "^9.3.8",
17+
"friendsofphp/php-cs-fixer": "^2.16"
1818
},
1919
"autoload" : {
2020
"psr-4": {

tests/AbstractShareTest.php

+33-65
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Icewind\SMB\Test;
99

10+
use Icewind\SMB\Exception\AlreadyExistsException;
1011
use Icewind\SMB\Exception\FileInUseException;
1112
use Icewind\SMB\Exception\InvalidPathException;
13+
use Icewind\SMB\Exception\InvalidResourceException;
14+
use Icewind\SMB\Exception\InvalidTypeException;
15+
use Icewind\SMB\Exception\NotEmptyException;
1216
use Icewind\SMB\Exception\NotFoundException;
1317
use Icewind\SMB\FileInfo;
1418
use Icewind\SMB\IFileInfo;
@@ -32,7 +36,7 @@ abstract class AbstractShareTest extends TestCase {
3236

3337
protected $config;
3438

35-
public function tearDown() {
39+
public function tearDown(): void {
3640
try {
3741
if ($this->share) {
3842
try {
@@ -142,9 +146,9 @@ public function testMkdir($name) {
142146

143147
/**
144148
* @dataProvider invalidPathProvider
145-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
146149
*/
147150
public function testMkdirInvalidPath($name) {
151+
$this->expectException(InvalidPathException::class);
148152
$this->share->mkdir($this->root . '/' . $name);
149153
$dirs = $this->share->dir($this->root);
150154
$this->assertCount(1, $dirs);
@@ -191,9 +195,9 @@ public function testPut($name, $text) {
191195

192196
/**
193197
* @dataProvider invalidPathProvider
194-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
195198
*/
196199
public function testPutInvalidPath($name) {
200+
$this->expectException(InvalidPathException::class);
197201
$tmpFile = $this->getTextFile('foo');
198202

199203
try {
@@ -237,10 +241,8 @@ public function testGet($name, $text) {
237241
unlink($targetFile);
238242
}
239243

240-
/**
241-
* @expectedException \Icewind\SMB\Exception\InvalidResourceException
242-
*/
243244
public function testGetInvalidTarget() {
245+
$this->expectException(InvalidResourceException::class);
244246
$name = 'test.txt';
245247
$text = 'dummy';
246248
$tmpFile = $this->getTextFile($text);
@@ -273,150 +275,120 @@ public function testNotFoundExceptionPath() {
273275
}
274276
}
275277

276-
/**
277-
* @expectedException \Icewind\SMB\Exception\NotFoundException
278-
*/
279278
public function testCreateFolderInNonExistingFolder() {
279+
$this->expectException(NotFoundException::class);
280280
$this->share->mkdir($this->root . '/foo/bar');
281281
}
282282

283-
/**
284-
* @expectedException \Icewind\SMB\Exception\NotFoundException
285-
*/
286283
public function testRemoveFolderInNonExistingFolder() {
284+
$this->expectException(NotFoundException::class);
287285
$this->share->rmdir($this->root . '/foo/bar');
288286
}
289287

290-
/**
291-
* @expectedException \Icewind\SMB\Exception\NotFoundException
292-
*/
293288
public function testRemoveNonExistingFolder() {
289+
$this->expectException(NotFoundException::class);
294290
$this->share->rmdir($this->root . '/foo');
295291
}
296292

297-
/**
298-
* @expectedException \Icewind\SMB\Exception\AlreadyExistsException
299-
*/
300293
public function testCreateExistingFolder() {
294+
$this->expectException(AlreadyExistsException::class);
301295
$this->share->mkdir($this->root . '/bar');
302296
$this->share->mkdir($this->root . '/bar');
303297
$this->share->rmdir($this->root . '/bar');
304298
}
305299

306-
/**
307-
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
308-
*/
309300
public function testCreateFileExistingFolder() {
301+
$this->expectException(InvalidTypeException::class);
310302
$this->share->mkdir($this->root . '/bar');
311303
$this->share->put($this->getTextFile(), $this->root . '/bar');
312304
$this->share->rmdir($this->root . '/bar');
313305
}
314306

315-
/**
316-
* @expectedException \Icewind\SMB\Exception\NotFoundException
317-
*/
318307
public function testCreateFileInNonExistingFolder() {
308+
$this->expectException(NotFoundException::class);
319309
$this->share->put($this->getTextFile(), $this->root . '/foo/bar');
320310
}
321311

322-
/**
323-
* @expectedException \Icewind\SMB\Exception\NotFoundException
324-
*/
325312
public function testTestRemoveNonExistingFile() {
313+
$this->expectException(NotFoundException::class);
326314
$this->share->del($this->root . '/foo');
327315
}
328316

329317
/**
330318
* @dataProvider invalidPathProvider
331-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
332319
*/
333320
public function testDownloadInvalidPath($name) {
321+
$this->expectException(InvalidPathException::class);
334322
$this->share->get($name, '');
335323
}
336324

337-
/**
338-
* @expectedException \Icewind\SMB\Exception\NotFoundException
339-
*/
340325
public function testDownloadNonExistingFile() {
326+
$this->expectException(NotFoundException::class);
341327
$this->share->get($this->root . '/foo', '/dev/null');
342328
}
343329

344-
/**
345-
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
346-
*/
347330
public function testDownloadFolder() {
331+
$this->expectException(InvalidTypeException::class);
348332
$this->share->mkdir($this->root . '/foobar');
349333
$this->share->get($this->root . '/foobar', '/dev/null');
350334
$this->share->rmdir($this->root . '/foobar');
351335
}
352336

353337
/**
354338
* @dataProvider invalidPathProvider
355-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
356339
*/
357340
public function testDelInvalidPath($name) {
341+
$this->expectException(InvalidPathException::class);
358342
$this->share->del($name);
359343
}
360344

361-
/**
362-
* @expectedException \Icewind\SMB\Exception\InvalidTypeException
363-
*/
364345
public function testRmdirFile() {
346+
$this->expectException(InvalidTypeException::class);
365347
$this->share->put($this->getTextFile(), $this->root . '/foobar');
366348
$this->share->rmdir($this->root . '/foobar');
367349
$this->share->del($this->root . '/foobar');
368350
}
369351

370-
/**
371-
* @expectedException \Icewind\SMB\Exception\NotEmptyException
372-
*/
373352
public function testRmdirNotEmpty() {
353+
$this->expectException(NotEmptyException::class);
374354
$this->share->mkdir($this->root . '/foobar');
375355
$this->share->put($this->getTextFile(), $this->root . '/foobar/asd');
376356
$this->share->rmdir($this->root . '/foobar');
377357
}
378358

379359
/**
380360
* @dataProvider invalidPathProvider
381-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
382361
*/
383362
public function testRmDirInvalidPath($name) {
363+
$this->expectException(InvalidPathException::class);
384364
$this->share->rmdir($name);
385365
}
386366

387-
/**
388-
* @expectedException \Icewind\SMB\Exception\NotFoundException
389-
*/
390367
public function testDirNonExisting() {
368+
$this->expectException(NotFoundException::class);
391369
$this->share->dir('/foobar/asd');
392370
}
393371

394-
/**
395-
* @expectedException \Icewind\SMB\Exception\NotFoundException
396-
*/
397372
public function testRmDirNonExisting() {
373+
$this->expectException(NotFoundException::class);
398374
$this->share->rmdir('/foobar/asd');
399375
}
400376

401-
/**
402-
* @expectedException \Icewind\SMB\Exception\NotFoundException
403-
*/
404377
public function testRenameNonExisting() {
378+
$this->expectException(NotFoundException::class);
405379
$this->share->rename('/foobar/asd', '/foobar/bar');
406380
}
407381

408382
/**
409383
* @dataProvider invalidPathProvider
410-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
411384
*/
412385
public function testRenameInvalidPath($name) {
386+
$this->expectException(InvalidPathException::class);
413387
$this->share->rename($name, $name . '_');
414388
}
415389

416-
/**
417-
* @expectedException \Icewind\SMB\Exception\NotFoundException
418-
*/
419390
public function testRenameTargetNonExisting() {
391+
$this->expectException(NotFoundException::class);
420392
$txt = $this->getTextFile();
421393
$this->share->put($txt, $this->root . '/foo.txt');
422394
unlink($txt);
@@ -448,9 +420,9 @@ public function testReadStream($name, $text) {
448420

449421
/**
450422
* @dataProvider invalidPathProvider
451-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
452423
*/
453424
public function testReadStreamInvalidPath($name) {
425+
$this->expectException(InvalidPathException::class);
454426
$this->share->read($name);
455427
}
456428

@@ -488,9 +460,9 @@ public function testAppendStream() {
488460

489461
/**
490462
* @dataProvider invalidPathProvider
491-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
492463
*/
493464
public function testWriteStreamInvalidPath($name) {
465+
$this->expectException(InvalidPathException::class);
494466
$fh = $this->share->write($this->root . '/' . $name);
495467
fwrite($fh, 'foo');
496468
fclose($fh);
@@ -525,9 +497,9 @@ public function testDir() {
525497

526498
/**
527499
* @dataProvider invalidPathProvider
528-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
529500
*/
530501
public function testDirInvalidPath($name) {
502+
$this->expectException(InvalidPathException::class);
531503
$this->share->dir($name);
532504
}
533505

@@ -547,16 +519,14 @@ public function testStat($name) {
547519

548520
/**
549521
* @dataProvider invalidPathProvider
550-
* @expectedException \Icewind\SMB\Exception\InvalidPathException
551522
*/
552523
public function testStatInvalidPath($name) {
524+
$this->expectException(InvalidPathException::class);
553525
$this->share->stat($name);
554526
}
555527

556-
/**
557-
* @expectedException \Icewind\SMB\Exception\NotFoundException
558-
*/
559528
public function testStatNonExisting() {
529+
$this->expectException(NotFoundException::class);
560530
$this->share->stat($this->root . '/fo.txt');
561531
}
562532

@@ -687,10 +657,8 @@ public function testStatRoot() {
687657
$this->assertInstanceOf('\Icewind\SMB\IFileInfo', $info);
688658
}
689659

690-
/**
691-
* @expectedException \Icewind\SMB\Exception\FileInUseException
692-
*/
693660
public function testMoveIntoSelf() {
661+
$this->expectException(FileInUseException::class);
694662
$this->share->mkdir($this->root . '/folder');
695663
$this->share->rename($this->root . '/folder', $this->root . '/folder/subfolder');
696664
}

tests/NativeShareTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Icewind\SMB\TimeZoneProvider;
1515

1616
class NativeShareTest extends AbstractShareTest {
17-
public function setUp() {
17+
public function setUp(): void {
1818
$this->requireBackendEnv('libsmbclient');
1919
if (!function_exists('smbclient_state_new')) {
2020
$this->markTestSkipped('libsmbclient php extension not installed');

tests/NativeStreamTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class NativeStreamTest extends TestCase {
3131

3232
protected $config;
3333

34-
public function setUp() {
34+
public function setUp(): void {
3535
$this->requireBackendEnv('libsmbclient');
3636
if (!function_exists('smbclient_state_new')) {
3737
$this->markTestSkipped('libsmbclient php extension not installed');
@@ -137,7 +137,7 @@ public function testSetOptionUnsupported() {
137137
$this->assertFalse(stream_set_blocking($fh, false));
138138
}
139139

140-
public function tearDown() {
140+
public function tearDown(): void {
141141
if ($this->share) {
142142
$this->cleanDir($this->root);
143143
}

tests/NotifyHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NotifyHandlerTest extends TestCase {
2626

2727
private $config;
2828

29-
public function setUp() {
29+
public function setUp(): void {
3030
$this->requireBackendEnv('smbclient');
3131
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
3232
$this->server = new Server(

tests/ServerFactoryTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace Icewind\SMB\Test;
2323

2424
use Icewind\SMB\AnonymousAuth;
25+
use Icewind\SMB\Exception\DependencyException;
2526
use Icewind\SMB\IAuth;
2627
use Icewind\SMB\Native\NativeServer;
2728
use Icewind\SMB\ServerFactory;
@@ -32,7 +33,7 @@ class ServerFactoryTest extends TestCase {
3233
/** @var IAuth */
3334
private $credentials;
3435

35-
protected function setUp() {
36+
protected function setUp(): void {
3637
parent::setUp();
3738

3839
$this->credentials = new AnonymousAuth();
@@ -59,10 +60,8 @@ public function testLibSmbClient() {
5960
$this->assertInstanceOf(NativeServer::class, $factory->createServer('localhost', $this->credentials));
6061
}
6162

62-
/**
63-
* @expectedException \Icewind\SMB\Exception\DependencyException
64-
*/
6563
public function testNoBackend() {
64+
$this->expectException(DependencyException::class);
6665
$this->requireBackendEnv('smbclient');
6766
$system = $this->getMockBuilder(System::class)
6867
->setMethods(['libSmbclientAvailable', 'getSmbclientPath'])

0 commit comments

Comments
 (0)