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 15, 2024
1 parent 864db82 commit db6b14f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 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
6 changes: 4 additions & 2 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
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 db6b14f

Please sign in to comment.