summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Uckelman <uckelman@nomic.net>2012-02-27 04:56:10 +0100
committerJoel Uckelman <uckelman@nomic.net>2012-02-27 04:56:10 +0100
commit8f10606385c6e0a77177e48d4072b5eb7c52da68 (patch)
tree79b308352c0569bb01ca5228b864ec644b4ec3a1
parentb62a32659d64c76ffbdea8072f19d77915800c86 (diff)
Fixed problem with expected exceptions.
-rw-r--r--src/HTTP_POST_multipart.php26
-rw-r--r--test/HTTP_POST_multipartTest.php27
2 files changed, 40 insertions, 13 deletions
diff --git a/src/HTTP_POST_multipart.php b/src/HTTP_POST_multipart.php
index a3faa27..ad80cb9 100644
--- a/src/HTTP_POST_multipart.php
+++ b/src/HTTP_POST_multipart.php
@@ -25,8 +25,12 @@ class HTTP_POST_multipart {
protected $_parts = array();
public function addData($name, $data) {
- if ($name === null) throw new Exception('name is null');
- if ($data === null) throw new Exception('data is null');
+ if ($name === null) {
+ throw new InvalidArgumentException('name is null');
+ }
+ if ($data === null) {
+ throw new InvalidArgumentException('data is null');
+ }
$this->_parts[] = array(
'name' => $name,
@@ -36,10 +40,18 @@ class HTTP_POST_multipart {
public function addFile($name, $filename, $mimetype,
$charset, $encoding, $data) {
- if ($name === null) throw new Exception('name is null');
- if ($filename === null) throw new Exception('filename is null');
- if ($mimetype === null) throw new Exception('mimetype is null');
- if ($data === null) throw new Exception('data is null');
+ if ($name === null) {
+ throw new InvalidArgumentException('name is null');
+ }
+ if ($filename === null) {
+ throw new InvalidArgumentException('filename is null');
+ }
+ if ($mimetype === null) {
+ throw new InvalidArgumentException('mimetype is null');
+ }
+ if ($data === null) {
+ throw new InvalidArgumentException('data is null');
+ }
$this->_parts[] = array(
'name' => $name,
@@ -82,7 +94,7 @@ class HTTP_POST_multipart {
$data = chunk_split(base64_encode($part['data']));
break;
default:
- throw new Exception('unrecognized encoding: ' . $part['encoding']);
+ throw new InvalidArgumentException('unrecognized encoding: ' . $part['encoding']);
}
}
else {
diff --git a/test/HTTP_POST_multipartTest.php b/test/HTTP_POST_multipartTest.php
index 5d7c32e..413bedf 100644
--- a/test/HTTP_POST_multipartTest.php
+++ b/test/HTTP_POST_multipartTest.php
@@ -33,7 +33,9 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerBuildDataPart
*/
public function testBuildDataPart($part, $expected, $ex) {
- if ($ex) $this->setExpectedException($ex);
+ if ($ex) {
+ $this->setExpectedException($ex);
+ }
$this->assertEquals(
$expected,
@@ -43,7 +45,6 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
public function providerBuildDataPart() {
return array(
- array(null, null, 'Exception'),
array(
array('name' => 'foo', 'data' => 1),
"Content-Disposition: form-data; name=\"foo\"\r\n\r\n1\r\n",
@@ -56,7 +57,9 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerBuildFilePart
*/
public function testBuildFilePart($part, $expected, $ex) {
- if ($ex) $this->setExpectedException($ex);
+ if ($ex) {
+ $this->setExpectedException($ex);
+ }
$this->assertEquals(
$expected,
@@ -66,7 +69,6 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
public function providerBuildFilePart() {
return array(
- array(null, null, 'Exception'),
array(
array(
'name' => 'foo',
@@ -102,6 +104,18 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
),
"Content-Disposition: form-data; name=\"foo\"; filename=\"somename.png\"\r\nContent-Type: image/png\r\nContent-Transfer-Encoding: base64\r\n\r\nYmxhaCBibGFoIGJsYWgKYmxhaCBibGFoIGJsYWg=\r\n\r\n",
null
+ ),
+ array(
+ array(
+ 'name' => 'foo',
+ 'filename' => 'somename.txt',
+ 'mimetype' => 'text/plain',
+ 'charset' => 'utf-8',
+ 'encoding' => 'bogus',
+ 'data' => "blah blah blah\nblah blah blah"
+ ),
+ null,
+ 'InvalidArgumentException'
)
);
}
@@ -110,7 +124,9 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerBuildPost
*/
public function testBuildPost($parts, $expected, $ex) {
- if ($ex) $this->setExpectedException($ex);
+ if ($ex) {
+ $this->setExpectedException($ex);
+ }
list($boundary, $content) =
self::getMethod('buildPost')->invokeArgs(null, array($parts));
@@ -121,7 +137,6 @@ class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase {
public function providerBuildPost() {
return array(
- array(null, null, 'Exception'),
array(
array(
array(