Browse Source

ORM\Error -> ORM\Exception

Jose Lorenzo Rodriguez 11 years ago
parent
commit
ce8db8598f

+ 17 - 11
src/ORM/BehaviorRegistry.php

@@ -14,12 +14,14 @@
  */
 namespace Cake\ORM;
 
+use BadMethodCallException;
 use Cake\Core\App;
-use Cake\Core\Exception\Exception;
+use Cake\Core\ObjectRegistry;
 use Cake\Event\EventManagerTrait;
 use Cake\ORM\Behavior;
+use Cake\ORM\Exception\MissingBehaviorException;
 use Cake\ORM\Table;
-use Cake\Core\ObjectRegistry;
+use LogicException;
 
 /**
  * BehaviorRegistry is used as a registry for loaded behaviors and handles loading
@@ -82,10 +84,10 @@ class BehaviorRegistry extends ObjectRegistry {
  * @param string $class The classname that is missing.
  * @param string $plugin The plugin the behavior is missing in.
  * @return void
- * @throws \Cake\ORM\Error\MissingBehaviorException
+ * @throws \Cake\ORM\Exception\MissingBehaviorException
  */
 	protected function _throwMissingClassError($class, $plugin) {
-		throw new Error\MissingBehaviorException([
+		throw new MissingBehaviorException([
 			'class' => $class . 'Behavior',
 			'plugin' => $plugin
 		]);
@@ -125,7 +127,7 @@ class BehaviorRegistry extends ObjectRegistry {
  * @param string $class The classname that is missing.
  * @param string $alias The alias of the object.
  * @return void
- * @throws \Cake\Core\Exception\Exception when duplicate methods are connected.
+ * @throws \LogicException when duplicate methods are connected.
  */
 	protected function _getMethods(Behavior $instance, $class, $alias) {
 		$finders = array_change_key_case($instance->implementedFinders());
@@ -140,7 +142,7 @@ class BehaviorRegistry extends ObjectRegistry {
 					$finder,
 					$duplicate[0]
 				);
-				throw new Exception($error);
+				throw new LogicException($error);
 			}
 			$finders[$finder] = [$alias, $methodName];
 		}
@@ -154,7 +156,7 @@ class BehaviorRegistry extends ObjectRegistry {
 					$method,
 					$duplicate[0]
 				);
-				throw new Exception($error);
+				throw new LogicException($error);
 			}
 			$methods[$method] = [$alias, $methodName];
 		}
@@ -196,7 +198,7 @@ class BehaviorRegistry extends ObjectRegistry {
  * @param string $method The method to invoke.
  * @param array $args The arguments you want to invoke the method with.
  * @return mixed The return value depends on the underlying behavior method.
- * @throws \Cake\Core\Exception\Exception When the method is unknown.
+ * @throws \BadMethodCallException When the method is unknown.
  */
 	public function call($method, array $args = []) {
 		$method = strtolower($method);
@@ -205,7 +207,9 @@ class BehaviorRegistry extends ObjectRegistry {
 			return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args);
 		}
 
-		throw new Exception(sprintf('Cannot call "%s" it does not belong to any attached behavior.', $method));
+		throw new BadMethodCallException(
+			sprintf('Cannot call "%s" it does not belong to any attached behavior.', $method)
+		);
 	}
 
 /**
@@ -214,7 +218,7 @@ class BehaviorRegistry extends ObjectRegistry {
  * @param string $type The finder type to invoke.
  * @param array $args The arguments you want to invoke the method with.
  * @return mixed The return value depends on the underlying behavior method.
- * @throws \Cake\Core\Exception\Exception When the method is unknown.
+ * @throws \BadMethodCallException When the method is unknown.
  */
 	public function callFinder($type, array $args = []) {
 		$type = strtolower($type);
@@ -224,7 +228,9 @@ class BehaviorRegistry extends ObjectRegistry {
 			return call_user_func_array([$this->_loaded[$behavior], $callMethod], $args);
 		}
 
-		throw new Exception(sprintf('Cannot call finder "%s" it does not belong to any attached behavior.', $type));
+		throw new BadMethodCallException(
+			sprintf('Cannot call finder "%s" it does not belong to any attached behavior.', $type)
+		);
 	}
 
 }

+ 1 - 1
src/ORM/Error/MissingBehaviorException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\ORM\Error;
+namespace Cake\ORM\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/ORM/Error/MissingEntityException.php

@@ -14,7 +14,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\ORM\Error;
+namespace Cake\ORM\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/ORM/Error/MissingTableClassException.php

@@ -12,7 +12,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\ORM\Error;
+namespace Cake\ORM\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/ORM/Error/RecordNotFoundException.php

@@ -12,7 +12,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\ORM\Error;
+namespace Cake\ORM\Exception;
 
 use RuntimeException;
 

+ 8 - 7
src/ORM/Table.php

@@ -14,6 +14,7 @@
  */
 namespace Cake\ORM;
 
+use BadMethodCallException;
 use Cake\Core\App;
 use Cake\Database\Schema\Table as Schema;
 use Cake\Database\Type;
@@ -29,8 +30,8 @@ use Cake\ORM\Association\BelongsToMany;
 use Cake\ORM\Association\HasMany;
 use Cake\ORM\Association\HasOne;
 use Cake\ORM\BehaviorRegistry;
-use Cake\ORM\Error\MissingEntityException;
-use Cake\ORM\Error\RecordNotFoundException;
+use Cake\ORM\Exception\MissingEntityException;
+use Cake\ORM\Exception\RecordNotFoundException;
 use Cake\ORM\Marshaller;
 use Cake\Utility\Inflector;
 use Cake\Validation\Validator;
@@ -431,7 +432,7 @@ class Table implements RepositoryInterface, EventListener {
  * a new one
  *
  * @param string $name the name of the class to use
- * @throws \Cake\ORM\Error\MissingEntityException when the entity class cannot be found
+ * @throws \Cake\ORM\Exception\MissingEntityException when the entity class cannot be found
  * @return string
  */
 	public function entityClass($name = null) {
@@ -889,7 +890,7 @@ class Table implements RepositoryInterface, EventListener {
 /**
  * {@inheritDoc}
  *
- * @throws \Cake\ORM\Error\RecordNotFoundException if no record can be found given
+ * @throws \Cake\ORM\Exception\RecordNotFoundException if no record can be found given
  * a primary key value.
  * @throws \InvalidArgumentException When $primaryKey has an incorrect number of elements.
  */
@@ -1461,7 +1462,7 @@ class Table implements RepositoryInterface, EventListener {
  * @param string $method The method name that was fired.
  * @param array $args List of arguments passed to the function.
  * @return mixed
- * @throws \Cake\Core\Exception\Exception when there are missing arguments, or when
+ * @throws \BadMethodCallException when there are missing arguments, or when
  *  and & or are combined.
  */
 	protected function _dynamicFinder($method, $args) {
@@ -1482,7 +1483,7 @@ class Table implements RepositoryInterface, EventListener {
 		$makeConditions = function($fields, $args) {
 			$conditions = [];
 			if (count($args) < count($fields)) {
-				throw new \Cake\Core\Exception\Exception(sprintf(
+				throw new BadMethodCallException(sprintf(
 					'Not enough arguments to magic finder. Got %s required %s',
 					count($args),
 					count($fields)
@@ -1495,7 +1496,7 @@ class Table implements RepositoryInterface, EventListener {
 		};
 
 		if ($hasOr !== false && $hasAnd !== false) {
-			throw new \Cake\Core\Exception\Exception(
+			throw new BadMethodCallException(
 				'Cannot mix "and" & "or" in a magic finder. Use find() instead.'
 			);
 		}

+ 2 - 2
src/TestSuite/TestCase.php

@@ -560,7 +560,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
  * @param string $alias The model to get a mock for.
  * @param mixed $methods The list of methods to mock
  * @param array $options The config data for the mock's constructor.
- * @throws \Cake\ORM\Error\MissingTableClassException
+ * @throws \Cake\ORM\Exception\MissingTableClassException
  * @return Model
  */
 	public function getMockForModel($alias, array $methods = array(), array $options = array()) {
@@ -568,7 +568,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
 			$class = Inflector::camelize($alias);
 			$className = App::className($class, 'Model/Table', 'Table');
 			if (!$className) {
-				throw new \Cake\ORM\Error\MissingTableClassException(array($alias));
+				throw new \Cake\ORM\Exception\MissingTableClassException(array($alias));
 			}
 			$options['className'] = $className;
 		}

+ 7 - 7
tests/TestCase/ORM/BehaviorRegistryTest.php

@@ -109,7 +109,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test load() on undefined class
  *
- * @expectedException \Cake\ORM\Error\MissingBehaviorException
+ * @expectedException \Cake\ORM\Exception\MissingBehaviorException
  * @return void
  */
 	public function testLoadMissingClass() {
@@ -119,7 +119,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test load() duplicate method error
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException LogicException
  * @expectedExceptionMessage TestApp\Model\Behavior\DuplicateBehavior contains duplicate method "slugify"
  * @return void
  */
@@ -149,7 +149,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test load() duplicate finder error
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException LogicException
  * @expectedExceptionMessage TestApp\Model\Behavior\DuplicateBehavior contains duplicate finder "children"
  * @return void
  */
@@ -243,7 +243,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test errors on unknown methods.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Cannot call "nope"
  */
 	public function testCallError() {
@@ -280,7 +280,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test errors on unknown methods.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Cannot call finder "nope"
  */
 	public function testCallFinderError() {
@@ -291,7 +291,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test errors on unloaded behavior methods.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Cannot call "slugify" it does not belong to any attached behavior.
  */
 	public function testUnloadBehaviorThenCall() {
@@ -304,7 +304,7 @@ class BehaviorRegistryTest extends TestCase {
 /**
  * Test errors on unloaded behavior finders.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Cannot call finder "noslug" it does not belong to any attached behavior.
  */
 	public function testUnloadBehaviorThenCallFinder() {

+ 6 - 6
tests/TestCase/ORM/TableTest.php

@@ -911,7 +911,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
  * Tests that using a simple string for entityClass will throw an exception
  * when the class does not exist in the namespace
  *
- * @expectedException \Cake\ORM\Error\MissingEntityException
+ * @expectedException \Cake\ORM\Exception\MissingEntityException
  * @expectedExceptionMessage Entity class FooUser could not be found.
  * @return void
  */
@@ -1101,7 +1101,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 /**
  * Ensure exceptions are raised on missing behaviors.
  *
- * @expectedException \Cake\ORM\Error\MissingBehaviorException
+ * @expectedException \Cake\ORM\Exception\MissingBehaviorException
  */
 	public function testAddBehaviorMissing() {
 		$table = TableRegistry::get('article');
@@ -2212,7 +2212,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 /**
  * Test magic findByXX errors on missing arguments.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Not enough arguments to magic finder. Got 0 required 1
  * @return void
  */
@@ -2225,7 +2225,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 /**
  * Test magic findByXX errors on missing arguments.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Not enough arguments to magic finder. Got 1 required 2
  * @return void
  */
@@ -2238,7 +2238,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 /**
  * Test magic findByXX errors when there is a mix of or & and.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException BadMethodCallException
  * @expectedExceptionMessage Cannot mix "and" & "or" in a magic finder. Use find() instead.
  * @return void
  */
@@ -3290,7 +3290,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 /**
  * Tests that get() will throw an exception if the record was not found
  *
- * @expectedException \Cake\ORM\Error\RecordNotFoundException
+ * @expectedException \Cake\ORM\Exception\RecordNotFoundException
  * @expectedExceptionMessage Record "10" not found in table "articles"
  * @return void
  */