From 095f87dae99a63b4079f0d005ab5139c5bfd84ee Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Mon, 10 Feb 2014 13:07:14 +0100 Subject: [PATCH] Fixes #73: Throw a RuntimeException when rawlist fails, this should be prevented in userland code. --- src/Adapter/Ftp.php | 4 ++++ tests/FtpTests.php | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Adapter/Ftp.php b/src/Adapter/Ftp.php index 17be10fd0..80f076e10 100644 --- a/src/Adapter/Ftp.php +++ b/src/Adapter/Ftp.php @@ -290,6 +290,10 @@ protected function listDirectoryContents($directory, $recursive = true) { $listing = ftp_rawlist($this->getConnection(), $directory, $recursive); + if ($listing === false) { + throw new RuntimeException('Could not perform a rawlist on directory: '.$directory); + } + return $this->normalizeListing($listing, $directory); } } diff --git a/tests/FtpTests.php b/tests/FtpTests.php index 1c27a7708..daff7e87b 100644 --- a/tests/FtpTests.php +++ b/tests/FtpTests.php @@ -81,8 +81,12 @@ function ftp_raw($connection, $command) return array( 0 => '211-Status of somewhere/folder/dummy.txt:', 1 => ' -rw-r--r-- 1 ftp ftp 0 Nov 24 13:59 somewhere/folder/dummy.txt', 2 => '211 End of status' ); } -function ftp_rawlist($connection) +function ftp_rawlist($connection, $directory) { + if (strpos($directory, 'fail.rawlist') !== false) { + return false; + } + return array( 'drwxr-xr-x 4 ftp ftp 4096 Nov 24 13:58 .', 'drwxr-xr-x 16 ftp ftp 4096 Sep 2 13:01 ..', @@ -147,23 +151,22 @@ function ftp_chmod($connection, $mode, $path) class FtpTests extends \PHPUnit_Framework_TestCase { + protected $options = array( + 'host' => 'example.org', + 'port' => 40, + 'ssl' => true, + 'timeout' => 35, + 'root' => '/somewhere', + 'permPublic' => 0777, + 'permPrivate' => 0000, + 'passive' => false, + 'username' => 'user', + 'password' => 'password', + ); + public function testInstantiable() { - // 'host', 'port', 'username', 'password', 'ssl', 'timeout', 'root', 'permPrivate', 'permPublic' - $options = array( - 'host' => 'example.org', - 'port' => 40, - 'ssl' => true, - 'timeout' => 35, - 'root' => '/somewhere', - 'permPublic' => 0777, - 'permPrivate' => 0000, - 'passive' => false, - 'username' => 'user', - 'password' => 'password', - ); - - $adapter = new Ftp($options); + $adapter = new Ftp($this->options); $this->assertEquals('example.org', $adapter->getHost()); $this->assertEquals(40, $adapter->getPort()); $this->assertEquals(true, $adapter->getSsl()); @@ -207,6 +210,15 @@ public function testConnectFail() $adapter->connect(); } + /** + * @expectedException RuntimeException + */ + public function testRawlistFail() + { + $adapter = new Ftp($this->options); + $adapter->listContents('fail.rawlist'); + } + /** * @expectedException RuntimeException */