diff --git a/Controller/Component/FilterComponent.php b/Controller/Component/FilterComponent.php index 81d9024..9db026a 100644 --- a/Controller/Component/FilterComponent.php +++ b/Controller/Component/FilterComponent.php @@ -153,7 +153,7 @@ public function beforeRender(Controller $controller) if (!isset($controller->$model)) { $errMsg = __('Filter model not found: %s', $model); if (is_string($errMsg)) { - trigger_error($errMsg); + throw new InvalidArgumentException($errMsg); } continue; } diff --git a/Test/Case/Controller/Component/FilterComponentTest.php b/Test/Case/Controller/Component/FilterComponentTest.php index a0b8dbd..510c79a 100644 --- a/Test/Case/Controller/Component/FilterComponentTest.php +++ b/Test/Case/Controller/Component/FilterComponentTest.php @@ -301,14 +301,30 @@ public function testNoModelFound(): void ); $this->Controller->filters = $testSettings; - $this->setExpectedException('PHPUnit_Framework_Error_Notice'); - $this->Controller->Components->trigger('initialize', array($this->Controller)); + try { + $this->Controller->Components->trigger('initialize', array($this->Controller)); + $this->fail('InvalidArgumentException was not thrown'); + } catch (InvalidArgumentException $e) { + $this->assertSame('Filter model not found: ThisModelDoesNotExist', $e->getMessage()); + } - //$this->expectError(); - $this->Controller->Components->trigger('startup', array($this->Controller)); + $sessionKey = sprintf('FilterPlugin.Filters.%s.%s', $this->Controller->name, $this->Controller->action); + $filterValues = array('ThisModelDoesNotExist' => array('title' => 'in')); + $this->Controller->Session->write($sessionKey, $filterValues); + try { + $this->Controller->Components->trigger('startup', array($this->Controller)); + $this->fail('InvalidArgumentException was not thrown'); + } catch (InvalidArgumentException $e) { + $this->assertSame('Filter model not found: ThisModelDoesNotExist', $e->getMessage()); + } + $this->Controller->Session->delete($sessionKey); - $this->setExpectedException('PHPUnit_Framework_Error_Notice'); - $this->Controller->Components->trigger('beforeRender', array($this->Controller)); + try { + $this->Controller->Components->trigger('beforeRender', array($this->Controller)); + $this->fail('InvalidArgumentException was not thrown'); + } catch (InvalidArgumentException $e) { + $this->assertSame('Filter model not found: ThisModelDoesNotExist', $e->getMessage()); + } } /**