diff --git a/core/ClassInfo.php b/core/ClassInfo.php index 5c08360d3..f22c8c3e9 100644 --- a/core/ClassInfo.php +++ b/core/ClassInfo.php @@ -93,7 +93,7 @@ class ClassInfo { if (is_object($class)) $class = get_class($class); if (!is_subclass_of($class, 'DataObject')) { - throw new Exception("$class is not a subclass of DataObject"); + throw new InvalidArgumentException("$class is not a subclass of DataObject"); } while ($next = get_parent_class($class)) { @@ -148,7 +148,7 @@ class ClassInfo { if (is_object($class)) { $class = get_class($class); } elseif (!is_string($class)) { - throw new Exception(sprintf( + throw new InvalidArgumentException(sprintf( 'Invalid class value %s, must be an object or string', var_export($class, true) )); } diff --git a/forms/GridField.php b/forms/GridField.php index 43141bf66..ba64b36e3 100644 --- a/forms/GridField.php +++ b/forms/GridField.php @@ -102,7 +102,7 @@ class GridField extends FormField { return $this->list->dataClass; } - throw new Exception(get_class($this).' does not have a modelClassName'); + throw new LogicException(get_class($this).' does not have a modelClassName'); } /** @@ -112,7 +112,7 @@ class GridField extends FormField { */ public function setPresenter($presenter) { if(!$presenter){ - throw new Exception('setPresenter() for GridField must be set with a class'); + throw new InvalidArgumentException('setPresenter() for GridField must be set with a class'); } if(is_object($presenter)) { @@ -123,11 +123,11 @@ class GridField extends FormField { } if(!class_exists($presenter)){ - throw new Exception('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.'); + throw new InvalidArgumentException('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.'); } - if($presenter !='GridFieldPresenter' && !ClassInfo::is_subclass_of($presenter, 'GridFieldPresenter')) { - throw new Exception(sprintf( + if($presenter !='GridFieldPresenter' && !is_subclass_of($presenter, 'GridFieldPresenter')) { + throw new InvalidArgumentException(sprintf( 'DataPresenter "%s" must subclass GridFieldPresenter', $presenter )); } diff --git a/forms/GridFieldPresenter.php b/forms/GridFieldPresenter.php index 9a79c4f35..a44623a88 100644 --- a/forms/GridFieldPresenter.php +++ b/forms/GridFieldPresenter.php @@ -181,7 +181,7 @@ class GridFieldPresenter extends ViewableData { */ public function Headers() { if(!$this->getList()) { - throw new Exception(sprintf( + throw new LogicException(sprintf( '%s needs an data source to be able to render the form', get_class($this->getGridField()) )); } diff --git a/tests/core/ClassInfoTest.php b/tests/core/ClassInfoTest.php index a34d9ccc4..619a496c3 100644 --- a/tests/core/ClassInfoTest.php +++ b/tests/core/ClassInfoTest.php @@ -48,7 +48,7 @@ class ClassInfoTest extends SapphireTest { $this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_ChildClass')); $this->assertEquals('ClassInfoTest_BaseClass', ClassInfo::baseDataClass('ClassInfoTest_GrandChildClass')); - $this->setExpectedException('Exception'); + $this->setExpectedException('InvalidArgumentException'); ClassInfo::baseDataClass('DataObject'); } @@ -71,7 +71,7 @@ class ClassInfoTest extends SapphireTest { '$tablesOnly option excludes memory-only inheritance classes' ); - $this->setExpectedException('Exception'); + $this->setExpectedException('InvalidArgumentException'); ClassInfo::ancestry(42); } diff --git a/tests/forms/GridFieldTest.php b/tests/forms/GridFieldTest.php index bda9385d1..424ac929a 100644 --- a/tests/forms/GridFieldTest.php +++ b/tests/forms/GridFieldTest.php @@ -32,19 +32,19 @@ class GridFieldTest extends SapphireTest { } function testSetEmptyDataPresenter() { - $this->setExpectedException('Exception'); + $this->setExpectedException('InvalidArgumentException'); $grid = new GridField('Testgrid'); $grid->setPresenter(''); } function testSetNonExistingDataPresenter() { - $this->setExpectedException('Exception'); + $this->setExpectedException('InvalidArgumentException'); $grid = new GridField('Testgrid'); $grid->setPresenter('ifThisClassExistsIWouldBeSurprised'); } function testSetDataPresenterWithDataObject() { - $this->setExpectedException('Exception'); + $this->setExpectedException('InvalidArgumentException'); $grid = new GridField('Testgrid'); $grid->setPresenter('DataObject'); } @@ -64,7 +64,7 @@ class GridFieldTest extends SapphireTest { * */ function testFieldHolderWithoutDataSource() { - $this->setExpectedException('Exception'); + $this->setExpectedException('LogicException'); $grid = new GridField('Testgrid'); $this->assertNotNull($grid->FieldHolder()); } diff --git a/tests/view/SSViewerCacheBlockTest.php b/tests/view/SSViewerCacheBlockTest.php index c1d4fbf95..0cae9d729 100644 --- a/tests/view/SSViewerCacheBlockTest.php +++ b/tests/view/SSViewerCacheBlockTest.php @@ -192,7 +192,7 @@ class SSViewerCacheBlockTest extends SapphireTest { } /** - * @expectedException Exception + * @expectedException SSTemplateParseException */ function testErrorMessageForCachedWithinControlWithinCached() { $this->_reset(true); @@ -205,7 +205,7 @@ class SSViewerCacheBlockTest extends SapphireTest { } /** - * @expectedException Exception + * @expectedException SSTemplateParseException */ function testErrorMessageForCachedWithinIf() { $this->_reset(true); @@ -213,7 +213,7 @@ class SSViewerCacheBlockTest extends SapphireTest { } /** - * @expectedException Exception + * @expectedException SSTemplateParseException */ function testErrorMessageForInvalidConditional() { $this->_reset(true);