Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'milestones/exceptions' of git://github.com/zendframewor…
Browse files Browse the repository at this point in the history
…k/zf2 into search
  • Loading branch information
prolic committed Oct 13, 2010
7 parents 6cfcb06 + 1bd47d3 + 83975c8 + cf20e25 + 926bdec + dd03435 + d106f99 commit 85a1daf
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/AbstractServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function _buildSignature(Reflection\AbstractFunction $reflection, $cla
$method = empty($ns) ? $name : $ns . '.' . $name;

if (!$this->_overwriteExistingMethods && $this->_table->hasMethod($method)) {
throw new Exception('Duplicate method registered: ' . $method);
throw new Exception\RuntimeException('Duplicate method registered: ' . $method);
}

$definition = new Method\Definition();
Expand Down
6 changes: 3 additions & 3 deletions src/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function addMethod($method, $name = null)
if (is_array($method)) {
$method = new Method\Definition($method);
} elseif (!$method instanceof Method\Definition) {
throw new Exception('Invalid method provided');
throw new Exception\InvalidArgumentException('Invalid method provided');
}

if (is_numeric($name)) {
Expand All @@ -98,11 +98,11 @@ public function addMethod($method, $name = null)
$name = $method->getName();
}
if (null === $name) {
throw new Exception('No method name provided');
throw new Exception\InvalidArgumentException('No method name provided');
}

if (!$this->_overwriteExistingMethods && array_key_exists($name, $this->_methods)) {
throw new Exception(sprintf('Method by name of "%s" already exists', $name));
throw new Exception\InvalidArgumentException(sprintf('Method by name of "%s" already exists', $name));
}
$this->_methods[$name] = $method;
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Exception
interface Exception
{
}
8 changes: 8 additions & 0 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Server\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\Server\Exception
{}
8 changes: 8 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Server\Exception;

class RuntimeException
extends \RuntimeException
implements \Zend\Server\Exception
{}
2 changes: 1 addition & 1 deletion src/Method/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function getMethod()
public function setType($type)
{
if (!in_array($type, $this->_types)) {
throw new Server\Exception('Invalid method callback type "' . $type . '" passed to ' . __CLASS__ . '::' . __METHOD__);
throw new Server\Exception\InvalidArgumentException('Invalid method callback type "' . $type . '" passed to ' . __CLASS__ . '::' . __METHOD__);
}
$this->_type = $type;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Method/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function setCallback($callback)
if (is_array($callback)) {
$callback = new Callback($callback);
} elseif (!$callback instanceof Callback) {
throw new Server\Exception('Invalid method callback provided');
throw new Server\Exception\InvalidArgumentException('Invalid method callback provided');
}
$this->_callback = $callback;
return $this;
Expand All @@ -160,7 +160,7 @@ public function addPrototype($prototype)
if (is_array($prototype)) {
$prototype = new Prototype($prototype);
} elseif (!$prototype instanceof Prototype) {
throw new Server\Exception('Invalid method prototype provided');
throw new Server\Exception\InvalidArgumentException('Invalid method prototype provided');
}
$this->_prototypes[] = $prototype;
return $this;
Expand Down Expand Up @@ -234,7 +234,7 @@ public function getMethodHelp()
public function setObject($object)
{
if (!is_object($object) && (null !== $object)) {
throw new Server\Exception('Invalid object passed to ' . __CLASS__ . '::' . __METHOD__);
throw new Server\Exception\InvalidArgumentException('Invalid object passed to ' . __CLASS__ . '::' . __METHOD__);
}
$this->_object = $object;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/Reflection/AbstractFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function __construct(\Reflector $r, $namespace = null, $argv = array())
// testing here.
if ((!$r instanceof \ReflectionFunction)
&& (!$r instanceof \ReflectionMethod)) {
throw new Exception('Invalid reflection class');
throw new Exception\InvalidArgumentException('Invalid reflection class');
}
$this->_reflection = $r;

Expand Down Expand Up @@ -334,7 +334,7 @@ protected function _reflect()
}

if (count($paramTypesTmp) != $paramCount) {
throw new Exception(
throw new Exception\RuntimeException(
'Variable number of arguments is not supported for services (except optional parameters). '
. 'Number of function arguments must correspond to actual number of arguments described in a docblock.');
}
Expand Down Expand Up @@ -365,7 +365,7 @@ public function __call($method, $args)
return call_user_func_array(array($this->_reflection, $method), $args);
}

throw new Exception('Invalid reflection method ("' .$method. '")');
throw new Exception\BadMethodCallException('Invalid reflection method ("' .$method. '")');
}

/**
Expand Down Expand Up @@ -414,7 +414,7 @@ public function setNamespace($namespace)
}

if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
throw new Exception('Invalid namespace');
throw new Exception\InvalidArgumentException('Invalid namespace');
}

$this->_namespace = $namespace;
Expand All @@ -439,7 +439,7 @@ public function getNamespace()
public function setDescription($string)
{
if (!is_string($string)) {
throw new Exception('Invalid description');
throw new Exception\InvalidArgumentException('Invalid description');
}

$this->_description = $string;
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Server\Exception
interface Exception extends \Zend\Server\Exception
{
}
8 changes: 8 additions & 0 deletions src/Reflection/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Server\Reflection\Exception;

class BadMethodCallException
extends \BadMethodCallException
implements \Zend\Server\Reflection\Exception
{}
8 changes: 8 additions & 0 deletions src/Reflection/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Server\Reflection\Exception;

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\Server\Reflection\Exception
{}
8 changes: 8 additions & 0 deletions src/Reflection/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Server\Reflection\Exception;

class RuntimeException
extends \RuntimeException
implements \Zend\Server\Reflection\Exception
{}
4 changes: 2 additions & 2 deletions src/Reflection/Prototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function __construct(ReflectionReturnValue $return, $params = null)
$this->_return = $return;

if (!is_array($params) && (null !== $params)) {
throw new Exception('Invalid parameters');
throw new Exception\InvalidArgumentException('Invalid parameters');
}

if (is_array($params)) {
foreach ($params as $param) {
if (!$param instanceof ReflectionParameter) {
throw new Exception('One or more params are invalid');
throw new Exception\InvalidArgumentException('One or more params are invalid');
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Reflection.php → src/Reflection/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @namespace
*/
namespace Zend\Server;
namespace Zend\Server\Reflection;

/**
* Reflection for determining method signatures to use with server classes
Expand Down Expand Up @@ -65,14 +65,14 @@ public static function reflectClass($class, $argv = false, $namespace = '')
} elseif (class_exists($class)) {
$reflection = new \ReflectionClass($class);
} else {
throw new Reflection\Exception('Invalid class or object passed to attachClass()');
throw new Exception\InvalidArgumentException('Invalid class or object passed to attachClass()');
}

if ($argv && !is_array($argv)) {
throw new Reflection\Exception('Invalid argv argument passed to reflectClass');
throw new Exception\InvalidArgumentException('Invalid argv argument passed to reflectClass');
}

return new Reflection\ReflectionClass($reflection, $namespace, $argv);
return new ReflectionClass($reflection, $namespace, $argv);
}

/**
Expand All @@ -95,14 +95,14 @@ public static function reflectClass($class, $argv = false, $namespace = '')
public static function reflectFunction($function, $argv = false, $namespace = '')
{
if (!is_string($function) || !function_exists($function)) {
throw new Reflection\Exception('Invalid function "' . $function . '" passed to reflectFunction');
throw new Exception\InvalidArgumentException('Invalid function "' . $function . '" passed to reflectFunction');
}


if ($argv && !is_array($argv)) {
throw new Reflection\Exception('Invalid argv argument passed to reflectClass');
throw new Exception\InvalidArgumentException('Invalid argv argument passed to reflectClass');
}

return new Reflection\ReflectionFunction(new \ReflectionFunction($function), $namespace, $argv);
return new ReflectionFunction(new \ReflectionFunction($function), $namespace, $argv);
}
}
4 changes: 2 additions & 2 deletions src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __call($method, $args)
return call_user_func_array(array($this->_reflection, $method), $args);
}

throw new Exception('Invalid reflection method');
throw new Exception\BadMethodCallException('Invalid reflection method');
}

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ public function setNamespace($namespace)
}

if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) {
throw new Exception('Invalid namespace');
throw new Exception\InvalidArgumentException('Invalid namespace');
}

$this->_namespace = $namespace;
Expand Down
6 changes: 3 additions & 3 deletions src/Reflection/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function __call($method, $args)
return call_user_func_array(array($this->_reflection, $method), $args);
}

throw new Exception('Invalid reflection method');
throw new Exception\BadMethodCallException('Invalid reflection method');
}

/**
Expand All @@ -111,7 +111,7 @@ public function getType()
public function setType($type)
{
if (!is_string($type) && (null !== $type)) {
throw new Exception('Invalid parameter type');
throw new Exception\InvalidArgumentException('Invalid parameter type');
}

$this->_type = $type;
Expand All @@ -136,7 +136,7 @@ public function getDescription()
public function setDescription($description)
{
if (!is_string($description) && (null !== $description)) {
throw new Exception('Invalid parameter description');
throw new Exception\InvalidArgumentException('Invalid parameter description');
}

$this->_description = $description;
Expand Down
4 changes: 2 additions & 2 deletions src/Reflection/ReflectionReturnValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getType()
public function setType($type)
{
if (!is_string($type) && (null !== $type)) {
throw new Exception('Invalid parameter type');
throw new Exception\InvalidArgumentException('Invalid parameter type');
}

$this->_type = $type;
Expand All @@ -107,7 +107,7 @@ public function getDescription()
public function setDescription($description)
{
if (!is_string($description) && (null !== $description)) {
throw new Exception('Invalid parameter description');
throw new Exception\InvalidArgumentException('Invalid parameter description');
}

$this->_description = $description;
Expand Down
4 changes: 1 addition & 3 deletions test/Method/CallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ public function testTypeShouldBeMutable()
$this->assertEquals('instance', $this->callback->getType());
}

/**
* @expectedException \Zend\Server\Exception
*/
public function testSettingTypeShouldThrowExceptionWhenInvalidTypeProvided()
{
$this->setExpectedException('Zend\Server\Exception\InvalidArgumentException', 'Invalid method callback type');
$this->callback->setType('bogus');
}

Expand Down
4 changes: 1 addition & 3 deletions test/Method/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ public function testObjectShouldBeMutable()
$this->assertEquals($object, $this->definition->getObject());
}

/**
* @expectedException Zend\Server\Exception
*/
public function testSettingObjectToNonObjectShouldThrowException()
{
$this->setExpectedException('Zend\Server\Exception\InvalidArgumentException', 'Invalid object passed to');
$this->definition->setObject('foo');
}

Expand Down
28 changes: 13 additions & 15 deletions test/Reflection/PrototypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,23 @@ public function tearDown()
*
* Returns: void
*/
public function test__construct()
public function testConstructWorks()
{
$this->assertTrue($this->_r instanceof Reflection\Prototype);

try {
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), $this->_parametersRaw);
$this->fail('Construction should only accept Z_S_R_Parameters');
} catch (\Exception $e) {
// do nothing
}

try {
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), 'string');
$this->fail('Construction requires an array of parameters');
} catch (\Exception $e) {
// do nothing
}
}

public function testConstructionThrowsExceptionOnInvalidParam()
{
$this->setExpectedException('Zend\Server\Reflection\Exception\InvalidArgumentException', 'One or more params are invalid');
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), $this->_parametersRaw);
}

public function testConstructionThrowsExceptionOnInvalidParamType()
{
$this->setExpectedException('Zend\Server\Reflection\Exception\InvalidArgumentException', 'Invalid parameters');
$r1 = new Reflection\Prototype($this->_r->getReturnValue(), 'string');
}

/**
* getReturnType() test
*
Expand Down
16 changes: 10 additions & 6 deletions test/Reflection/ReflectionFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ public function test__construct()
$this->assertTrue($r instanceof Reflection\ReflectionFunction);
$this->assertTrue($r instanceof Reflection\AbstractFunction);
$params = $r->getParameters();
try {
$r = new Reflection\ReflectionFunction($params[0]);
$this->fail('Should not be able to construct with non-function');
} catch (\Exception $e) {
// do nothing
}

$r = new Reflection\ReflectionFunction($function, 'namespace');
$this->assertEquals('namespace', $r->getNamespace());
Expand All @@ -64,6 +58,16 @@ public function test__construct()
$this->assertTrue(is_array($prototypes));
$this->assertTrue(0 < count($prototypes));
}

public function testConstructorThrowsExceptionOnNonFunction()
{
$function = new \ReflectionFunction('\ZendTest\Server\Reflection\function1');
$r = new Reflection\ReflectionFunction($function);
$params = $r->getParameters();

$this->setExpectedException('Zend\Server\Reflection\Exception\InvalidArgumentException', 'Invalid reflection class');
$r = new Reflection\ReflectionFunction($params[0]);
}

public function test__getSet()
{
Expand Down

0 comments on commit 85a1daf

Please sign in to comment.