Skip to content

Commit

Permalink
Presenter, LinkGenerator: exception 'missing corresponding method' im…
Browse files Browse the repository at this point in the history
…proved
  • Loading branch information
dg committed Apr 16, 2024
1 parent 599cbe5 commit 38646d0
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Application/LinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function link(string $dest, array $params = []): string
throw new UI\InvalidLinkException("Missing parameter \${$rp->getName()} required by $class::{$method->getName()}()");
}
} elseif (array_key_exists(0, $params)) {
throw new UI\InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method.");
throw new UI\InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method $class::{$class::formatRenderMethod($action)}().");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Application/UI/LinkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function generateUrl(
static::argsToParams($presenterClass, $method->getName(), $args, $path === 'this' ? $this->presenter->getParameters() : [], $missing);

} elseif (array_key_exists(0, $args)) {
throw new InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method.");
throw new InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method $presenterClass::{$presenterClass::formatRenderMethod($action)}().");
}

// counterpart of StatePersistent
Expand Down
2 changes: 1 addition & 1 deletion tests/Routers/LinkGenerator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace {
Assert::exception(function () use ($pf) {
$generator = new LinkGenerator(new Routers\Route('/', 'Homepage:'), new Http\UrlScript('http://nette.org/en/'), $pf);
$generator->link('Homepage:missing', [10]);
}, Nette\Application\UI\InvalidLinkException::class, "Unable to pass parameters to action 'Homepage:missing', missing corresponding method.");
}, Nette\Application\UI\InvalidLinkException::class, "Unable to pass parameters to action 'Homepage:missing', missing corresponding method HomepagePresenter::renderMissing().");


test('', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/UI/Presenter.link().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class TestPresenter extends Application\UI\Presenter
Assert::same('/index.php?sort%5By%5D%5Basc%5D=1&action=default&presenter=Test', $this->link('this', ['sort' => ['y' => ['asc' => true]]]));
Assert::same(['sort' => ['y' => ['asc' => true]], 'pint' => null, 'parr' => null, 'pbool' => null, 'mycontrol-order' => null, 'mycontrol-round' => null, 'action' => 'default'], $this->getLastCreatedRequest()->getParameters());

Assert::same("#error: Unable to pass parameters to action 'Test:product', missing corresponding method.", $this->link('product', 1));
Assert::same("#error: Unable to pass parameters to action 'Test:product', missing corresponding method TestPresenter::renderProduct().", $this->link('product', 1));
Assert::same('/index.php?a=1&action=product&presenter=Test', $this->link('product', ['a' => 1]));
Assert::same('#error: Passed more parameters than method TestPresenter::actionParams() expects.', $this->link('params', 1, 2, 3, 4, 5));

Expand Down

0 comments on commit 38646d0

Please sign in to comment.