Skip to content

Commit

Permalink
PresenterFactory: default mapping is App\UI\*\**Presenter (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 27, 2024
1 parent dbe6421 commit 57bd587
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Application/PresenterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PresenterFactory implements IPresenterFactory
{
/** @var array[] of module => splited mask */
private array $mapping = [
'*' => ['', '*Module\\', '*Presenter'],
'*' => ['App\\UI\\', '*\\', '**Presenter'],
'Nette' => ['NetteModule\\', '*\\', '*Presenter'],
];

Expand Down
18 changes: 9 additions & 9 deletions tests/Application/PresenterFactory.formatPresenterClass.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test('defined module', function () {
'Foo3' => 'My\App\*Mod\*Presenter',
]);

Assert::same('FooPresenter', $factory->formatPresenterClass('Foo'));
Assert::same('FooModule\BarPresenter', $factory->formatPresenterClass('Foo:Bar'));
Assert::same('FooModule\BarModule\BazPresenter', $factory->formatPresenterClass('Foo:Bar:Baz'));
Assert::same('App\UI\Foo\FooPresenter', $factory->formatPresenterClass('Foo'));
Assert::same('App\UI\Foo\Bar\BarPresenter', $factory->formatPresenterClass('Foo:Bar'));
Assert::same('App\UI\Foo\Bar\Baz\BazPresenter', $factory->formatPresenterClass('Foo:Bar:Baz'));

Assert::same('Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App\UI\Foo2\Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App2\BarPresenter', $factory->formatPresenterClass('Foo2:Bar'));
Assert::same('App2\Bar\BazPresenter', $factory->formatPresenterClass('Foo2:Bar:Baz'));

Expand All @@ -44,7 +44,7 @@ test('auto module', function () {
'Foo3' => 'My\App\*Presenter',
]);

Assert::same('Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App\UI\Foo2\Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App2\BarPresenter', $factory->formatPresenterClass('Foo2:Bar'));
Assert::same('App2\BarModule\BazPresenter', $factory->formatPresenterClass('Foo2:Bar:Baz'));

Expand All @@ -61,11 +61,11 @@ test('location ** & defined module', function () {
'Foo3' => 'My\App\*Mod\**Presenter',
]);

Assert::same('FooPresenter', $factory->formatPresenterClass('Foo'));
Assert::same('FooModule\BarPresenter', $factory->formatPresenterClass('Foo:Bar'));
Assert::same('FooModule\BarModule\BazPresenter', $factory->formatPresenterClass('Foo:Bar:Baz'));
Assert::same('App\UI\Foo\FooPresenter', $factory->formatPresenterClass('Foo'));
Assert::same('App\UI\Foo\Bar\BarPresenter', $factory->formatPresenterClass('Foo:Bar'));
Assert::same('App\UI\Foo\Bar\Baz\BazPresenter', $factory->formatPresenterClass('Foo:Bar:Baz'));

Assert::same('Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App\UI\Foo2\Foo2Presenter', $factory->formatPresenterClass('Foo2'));
Assert::same('App2\Bar\BarPresenter', $factory->formatPresenterClass('Foo2:Bar'));
Assert::same('App2\Bar\Baz\BazPresenter', $factory->formatPresenterClass('Foo2:Bar:Baz'));

Expand Down
8 changes: 5 additions & 3 deletions tests/Routers/LinkGenerator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

declare(strict_types=1);

namespace {
namespace App\UI\Homepage {

use Nette;

require __DIR__ . '/../bootstrap.php';

Expand All @@ -24,7 +26,7 @@ namespace {

}

namespace ModuleModule {
namespace App\UI\Module\My {

use Nette;

Expand Down Expand Up @@ -77,7 +79,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 HomepagePresenter::renderMissing().");
}, Nette\Application\UI\InvalidLinkException::class, "Unable to pass parameters to action 'Homepage:missing', missing corresponding method App\\UI\\Homepage\\HomepagePresenter::renderMissing().");


test('', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/Routers/link-aliases.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TestPresenter extends Application\UI\Presenter


$factory = new PresenterFactory;
$factory->setMapping(['*' => '*Presenter']);
$factory->setAliases([
'a' => 'Test:a',
'b' => 'Test:b',
Expand Down

0 comments on commit 57bd587

Please sign in to comment.