Skip to content

Commit

Permalink
Provide bare minimum tests update for extracted default listeners for…
Browse files Browse the repository at this point in the history
… Application.

Signed-off-by: Aleksei Khudiakov <[email protected]>
  • Loading branch information
Xerkus committed Dec 10, 2023
1 parent 1a79dc8 commit 4321411
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 119 deletions.
5 changes: 4 additions & 1 deletion src/ApplicationListenersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
use const SORT_REGULAR;

/**
* Provides lazy container
* Double-dispatch listener provider for Application to ensure default listeners and to ensure listeners attached
* once on Application instantiation.
*
* Delays fetching listener aggregates from container until attempt to attach them is made.
*/
final class ApplicationListenersProvider
{
Expand Down
34 changes: 17 additions & 17 deletions test/Application/BadControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Laminas\Http\PhpEnvironment\Request;
use Laminas\Http\PhpEnvironment\Response;
use Laminas\Mvc\Application;
use Laminas\Mvc\ConfigProvider;
use Laminas\Mvc\Controller\ControllerManager;
use Laminas\Router\ConfigProvider;
use Laminas\Router;
use Laminas\Router\Http\Literal;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
Expand All @@ -21,8 +22,8 @@ trait BadControllerTrait
{
public function prepareApplication(): Application
{
$config = [
'router' => [
$testConfig = [
'router' => [
'routes' => [
'path' => [
'type' => Literal::class,
Expand All @@ -36,14 +37,7 @@ public function prepareApplication(): Application
],
],
],
];

$serviceConfig = ArrayUtils::merge(
ArrayUtils::merge(
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
(new ConfigProvider())->getDependencyConfig(),
),
[
'dependencies' => [
'aliases' => [
'ControllerLoader' => ControllerManager::class,
],
Expand All @@ -62,13 +56,19 @@ public function prepareApplication(): Application
'SendResponseListener' => MockSendResponseListener::class,
'BootstrapListener' => StubBootstrapListener::class,
],
'services' => [
'config' => $config,
],
]
],
];

$config = ArrayUtils::merge(
ArrayUtils::merge(
(new ConfigProvider())(),
(new Router\ConfigProvider())(),
),
$testConfig
);
$services = new ServiceManager($serviceConfig);
$application = $services->get('Application');
$config['dependencies']['services']['config'] = $config;
$services = new ServiceManager($config['dependencies']);
$application = $services->get('Application');

$request = $services->get('Request');
$request->setUri('http://example.local/bad');
Expand Down
36 changes: 18 additions & 18 deletions test/Application/InvalidControllerTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Laminas\Http\PhpEnvironment\Request;
use Laminas\Http\PhpEnvironment\Response;
use Laminas\Mvc\Application;
use Laminas\Mvc\ConfigProvider;
use Laminas\Mvc\Controller\ControllerManager;
use Laminas\Router\ConfigProvider;
use Laminas\Router;
use Laminas\Router\Http\Literal;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
Expand All @@ -21,8 +22,8 @@ trait InvalidControllerTypeTrait
{
public function prepareApplication(): Application
{
$config = [
'router' => [
$testConfig = [
'router' => [
'routes' => [
'path' => [
'type' => Literal::class,
Expand All @@ -36,14 +37,7 @@ public function prepareApplication(): Application
],
],
],
];

$serviceConfig = ArrayUtils::merge(
ArrayUtils::merge(
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
(new ConfigProvider())->getDependencyConfig(),
),
[
'dependencies' => [
'aliases' => [
'ControllerLoader' => 'ControllerManager',
],
Expand All @@ -53,7 +47,6 @@ public function prepareApplication(): Application
'bad' => static fn(): stdClass => new stdClass(),
],
]),
'Router' => static fn($services) => $services->get('HttpRouter'),
],
'invokables' => [
'Request' => Request::class,
Expand All @@ -62,13 +55,20 @@ public function prepareApplication(): Application
'SendResponseListener' => MockSendResponseListener::class,
'BootstrapListener' => StubBootstrapListener::class,
],
'services' => [
'config' => $config,
],
]
],
];

$config = ArrayUtils::merge(
ArrayUtils::merge(
(new ConfigProvider())(),
(new Router\ConfigProvider())(),
),
$testConfig
);
$services = new ServiceManager($serviceConfig);
$application = $services->get('Application');
$config['dependencies']['services']['config'] = $config;

$services = new ServiceManager($config['dependencies']);
$application = $services->get('Application');

$request = $services->get('Request');
$request->setUri('http://example.local/bad');
Expand Down
39 changes: 19 additions & 20 deletions test/Application/MissingControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use Laminas\Http\PhpEnvironment\Request;
use Laminas\Http\PhpEnvironment\Response;
use Laminas\Mvc\Application;
use Laminas\Router\ConfigProvider;
use Laminas\Mvc\ConfigProvider;
use Laminas\Router;
use Laminas\Router\Http\Literal;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
Expand All @@ -19,8 +20,8 @@ trait MissingControllerTrait
{
public function prepareApplication(): Application
{
$config = [
'router' => [
$testConfig = [
'router' => [
'routes' => [
'path' => [
'type' => Literal::class,
Expand All @@ -34,31 +35,29 @@ public function prepareApplication(): Application
],
],
],
];

$serviceConfig = ArrayUtils::merge(
ArrayUtils::merge(
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
(new ConfigProvider())->getDependencyConfig(),
),
[
'factories' => [
'Router' => static fn($services) => $services->get('HttpRouter'),
],
'dependencies' => [
'invokables' => [
'Request' => Request::class,
'Response' => Response::class,
'ViewManager' => MockViewManager::class,
'SendResponseListener' => MockSendResponseListener::class,
'BootstrapListener' => StubBootstrapListener::class,
],
'services' => [
'config' => $config,
],
]
],
];

$config = ArrayUtils::merge(
ArrayUtils::merge(
(new ConfigProvider())(),
(new Router\ConfigProvider())(),
),
$testConfig
);
$services = new ServiceManager($serviceConfig);
$application = $services->get('Application');

$config['dependencies']['services']['config'] = $config;

$services = new ServiceManager($config['dependencies']);
$application = $services->get('Application');

$request = $services->get('Request');
$request->setUri('http://example.local/bad');
Expand Down
33 changes: 16 additions & 17 deletions test/Application/PathControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ trait PathControllerTrait
{
public function prepareApplication(): Application
{
$config = [
'router' => [
$testConfig = [
'router' => [
'routes' => [
'path' => [
'type' => Literal::class,
Expand All @@ -36,14 +36,7 @@ public function prepareApplication(): Application
],
],
],
];

$serviceConfig = ArrayUtils::merge(
ArrayUtils::merge(
(new ConfigProvider())->getDependencies(),
(new Router\ConfigProvider())->getDependencyConfig(),
),
[
'dependencies' => [
'aliases' => [
'ControllerLoader' => ControllerManager::class,
],
Expand All @@ -53,7 +46,6 @@ public function prepareApplication(): Application
'path' => static fn() => new TestAsset\PathController(),
],
]),
'Router' => static fn($services) => $services->get('HttpRouter'),
],
'invokables' => [
'Request' => Request::class,
Expand All @@ -62,13 +54,20 @@ public function prepareApplication(): Application
'SendResponseListener' => MockSendResponseListener::class,
'BootstrapListener' => StubBootstrapListener::class,
],
'services' => [
'config' => $config,
],
]
],
];

$config = ArrayUtils::merge(
ArrayUtils::merge(
(new ConfigProvider())(),
(new Router\ConfigProvider())(),
),
$testConfig
);
$services = new ServiceManager($serviceConfig);
$application = $services->get('Application');
$config['dependencies']['services']['config'] = $config;

$services = new ServiceManager($config['dependencies']);
$application = $services->get('Application');

$request = $services->get('Request');
$request->setUri('http://example.local/path');
Expand Down
Loading

0 comments on commit 4321411

Please sign in to comment.