Move to PSR-4 for autoloading

This commit is contained in:
Robin Appelman 2014-04-07 13:54:49 +02:00
commit 46e2daf1ee
12 changed files with 55 additions and 56 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.idea .idea
vendor

17
composer.json Normal file
View file

@ -0,0 +1,17 @@
{
"name" : "Icewind/SMB",
"description" : "php wrapper from smbclient",
"minimum-stability": "stable",
"license" : "AGPL 3",
"authors" : [
{
"name" : "Robin Appelman",
"email": "icewind@owncloud.com"
}
],
"autoload": {
"psr-4": {
"Icewind\\SMB\\": "src/"
}
}
}

View file

@ -6,7 +6,7 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace SMB; namespace Icewind\SMB;
class Connection extends RawConnection { class Connection extends RawConnection {
const DELIMITER = 'smb:'; const DELIMITER = 'smb:';

View file

@ -6,7 +6,7 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace SMB; namespace Icewind\SMB;
class NotFoundException extends \Exception { class NotFoundException extends \Exception {
} }

View file

@ -6,7 +6,7 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace SMB; namespace Icewind\SMB;
class RawConnection { class RawConnection {
/** /**

View file

@ -6,7 +6,7 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace SMB; namespace Icewind\SMB;
class Server { class Server {
const CLIENT = 'smbclient'; const CLIENT = 'smbclient';
@ -68,8 +68,8 @@ class Server {
/** /**
* @return Share[] * @return Share[]
* @throws \SMB\AuthenticationException * @throws \Icewind\SMB\AuthenticationException
* @throws \SMB\InvalidHostException * @throws \Icewind\SMB\InvalidHostException
*/ */
public function listShares() { public function listShares() {
$user = escapeshellarg($this->getUser()); $user = escapeshellarg($this->getUser());

View file

@ -6,7 +6,7 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
namespace SMB; namespace Icewind\SMB;
class Share { class Share {
/** /**

View file

@ -1,19 +0,0 @@
<?php
/**
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__);
require_once 'errors.php';
spl_autoload_register(function ($class) {
if (substr($class, 0, 4) == 'SMB\\') {
$class = strtolower($class);
$file = str_replace('\\', '/', substr($class, 4));
include __DIR__ . '/' . $file . '.php';
}
});

View file

@ -7,4 +7,4 @@
*/ */
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
require_once __DIR__.'/../src/autoload.php'; require_once __DIR__.'/../vendor/autoload.php';

View file

@ -1,7 +1,7 @@
{ {
"host": "VM", "host": "localhost",
"user": "VM\\test", "user": "test",
"password": "test", "password": "test",
"share": "Users", "share": "test",
"root": "test" "root": "test"
} }

View file

@ -4,7 +4,7 @@ namespace SMB\Test;
class Server extends \PHPUnit_Framework_TestCase { class Server extends \PHPUnit_Framework_TestCase {
/** /**
* @var \SMB\Server $server * @var \Icewind\SMB\Server $server
*/ */
private $server; private $server;
@ -12,7 +12,7 @@ class Server extends \PHPUnit_Framework_TestCase {
public function setUp() { public function setUp() {
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json')); $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new \SMB\Server($this->config->host, $this->config->user, $this->config->password); $this->server = new \Icewind\SMB\Server($this->config->host, $this->config->user, $this->config->password);
} }
public function testListShares() { public function testListShares() {
@ -26,31 +26,31 @@ class Server extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\AuthenticationException * @expectedException \Icewind\SMB\AuthenticationException
*/ */
public function testWrongUserName() { public function testWrongUserName() {
$server = new \SMB\Server($this->config->host, uniqid(), $this->config->password); $server = new \Icewind\SMB\Server($this->config->host, uniqid(), $this->config->password);
$server->listShares(); $server->listShares();
} }
/** /**
* @expectedException \SMB\AuthenticationException * @expectedException \Icewind\SMB\AuthenticationException
*/ */
public function testWrongPassword() { public function testWrongPassword() {
$server = new \SMB\Server($this->config->host, $this->config->user, uniqid()); $server = new \Icewind\SMB\Server($this->config->host, $this->config->user, uniqid());
$server->listShares(); $server->listShares();
} }
/** /**
* @expectedException \SMB\InvalidHostException * @expectedException \Icewind\SMB\InvalidHostException
*/ */
public function testWrongHost() { public function testWrongHost() {
$server = new \SMB\Server(uniqid(), $this->config->user, $this->config->password); $server = new \Icewind\SMB\Server(uniqid(), $this->config->user, $this->config->password);
$server->listShares(); $server->listShares();
} }
public function testGetTimeZone() { public function testGetTimeZone() {
$timeZone = $this->server->getTimeZone(); $timeZone = $this->server->getTimeZone();
$this->assertEquals('+0100', $timeZone); $this->assertEquals('+0200', $timeZone);
} }
} }

View file

@ -4,12 +4,12 @@ namespace SMB\Test;
class Share extends \PHPUnit_Framework_TestCase { class Share extends \PHPUnit_Framework_TestCase {
/** /**
* @var \SMB\Server $server * @var \Icewind\SMB\Server $server
*/ */
private $server; private $server;
/** /**
* @var \SMB\Share $share * @var \Icewind\SMB\Share $share
*/ */
private $share; private $share;
@ -22,7 +22,7 @@ class Share extends \PHPUnit_Framework_TestCase {
public function setUp() { public function setUp() {
$this->config = json_decode(file_get_contents(__DIR__ . '/config.json')); $this->config = json_decode(file_get_contents(__DIR__ . '/config.json'));
$this->server = new \SMB\Server($this->config->host, $this->config->user, $this->config->password); $this->server = new \Icewind\SMB\Server($this->config->host, $this->config->user, $this->config->password);
$this->share = $this->server->getShare($this->config->share); $this->share = $this->server->getShare($this->config->share);
if ($this->config->root) { if ($this->config->root) {
$this->root = '/' . $this->config->root . '/' . uniqid(); $this->root = '/' . $this->config->root . '/' . uniqid();
@ -118,7 +118,7 @@ class Share extends \PHPUnit_Framework_TestCase {
public function testEscaping() { public function testEscaping() {
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working // / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
$names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ'); $names = array('simple', 'with spaces', "single'quote'", '$as#d', '€', '££Ö€ßœĚęĘĞĜΣΥΦΩΫΫ', '_under - score');
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'; $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
$tmpFile1 = tempnam('/tmp', 'smb_test_'); $tmpFile1 = tempnam('/tmp', 'smb_test_');
@ -174,28 +174,28 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testCreateFolderInNonExistingFolder() { public function testCreateFolderInNonExistingFolder() {
$this->share->mkdir($this->root . '/foo/bar'); $this->share->mkdir($this->root . '/foo/bar');
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testRemoveFolderInNonExistingFolder() { public function testRemoveFolderInNonExistingFolder() {
$this->share->rmdir($this->root . '/foo/bar'); $this->share->rmdir($this->root . '/foo/bar');
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testRemoveNonExistingFolder() { public function testRemoveNonExistingFolder() {
$this->share->rmdir($this->root . '/foo'); $this->share->rmdir($this->root . '/foo');
} }
/** /**
* @expectedException \SMB\AlreadyExistsException * @expectedException \Icewind\SMB\AlreadyExistsException
*/ */
public function testCreateExistingFolder() { public function testCreateExistingFolder() {
$this->share->mkdir($this->root . '/bar'); $this->share->mkdir($this->root . '/bar');
@ -204,7 +204,7 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\InvalidTypeException * @expectedException \Icewind\SMB\InvalidTypeException
*/ */
public function testCreateFileExistingFolder() { public function testCreateFileExistingFolder() {
$this->share->mkdir($this->root . '/bar'); $this->share->mkdir($this->root . '/bar');
@ -213,28 +213,28 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testCreateFileInNonExistingFolder() { public function testCreateFileInNonExistingFolder() {
$this->share->put($this->getTextFile(), $this->root . '/foo/bar'); $this->share->put($this->getTextFile(), $this->root . '/foo/bar');
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testTestRemoveNonExistingFile() { public function testTestRemoveNonExistingFile() {
$this->share->del($this->root . '/foo'); $this->share->del($this->root . '/foo');
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testDownloadNonExistingFile() { public function testDownloadNonExistingFile() {
$this->share->get($this->root . '/foo', '/dev/null'); $this->share->get($this->root . '/foo', '/dev/null');
} }
/** /**
* @expectedException \SMB\InvalidTypeException * @expectedException \Icewind\SMB\InvalidTypeException
*/ */
public function testDownloadFolder() { public function testDownloadFolder() {
$this->share->mkdir($this->root . '/foobar'); $this->share->mkdir($this->root . '/foobar');
@ -243,7 +243,7 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testDelFolder() { public function testDelFolder() {
$this->share->mkdir($this->root . '/foobar'); $this->share->mkdir($this->root . '/foobar');
@ -252,7 +252,7 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\InvalidTypeException * @expectedException \Icewind\SMB\InvalidTypeException
*/ */
public function testRmdirFile() { public function testRmdirFile() {
$this->share->put($this->getTextFile(), $this->root . '/foobar'); $this->share->put($this->getTextFile(), $this->root . '/foobar');
@ -261,14 +261,14 @@ class Share extends \PHPUnit_Framework_TestCase {
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testDirNonExisting() { public function testDirNonExisting() {
$this->share->dir('/foobar/asd'); $this->share->dir('/foobar/asd');
} }
/** /**
* @expectedException \SMB\NotFoundException * @expectedException \Icewind\SMB\NotFoundException
*/ */
public function testRmDirNonExisting() { public function testRmDirNonExisting() {
$this->share->rmdir('/foobar/asd'); $this->share->rmdir('/foobar/asd');