Skip to content

Commit

Permalink
fixed testNoModelFound in FilterComponentTest.php #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Stich committed May 29, 2024
1 parent 1e27ad6 commit ce74bd0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Controller/Component/FilterComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 22 additions & 6 deletions Test/Case/Controller/Component/FilterComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 307 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.2)

Dead catch - InvalidArgumentException is never thrown in the try block.

Check failure on line 307 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Dead catch - InvalidArgumentException is never thrown in the try block.
$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);

Check failure on line 311 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.2)

Unreachable statement - code above always terminates.

Check failure on line 311 in Test/Case/Controller/Component/FilterComponentTest.php

View workflow job for this annotation

GitHub Actions / phpstan (8.3)

Unreachable statement - code above always terminates.
$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());
}
}

/**
Expand Down

0 comments on commit ce74bd0

Please sign in to comment.