Skip to content

Commit e9e7103

Browse files
committed
Provide bare minimum tests update for extracted default listeners for Application.
Signed-off-by: Aleksei Khudiakov <aleksey@xerkus.pro>
1 parent 18572bc commit e9e7103

File tree

6 files changed

+93
-119
lines changed

6 files changed

+93
-119
lines changed

src/ApplicationListenerProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
use const SORT_REGULAR;
1818

1919
/**
20-
* Provides lazy container
20+
* Double-dispatch listener provider for Application to ensure default listeners and to ensure listeners attached
21+
* once on Application instantiation.
22+
*
23+
* Delays fetching listener aggregates from container until attempt to attach them is made.
2124
*/
2225
final class ApplicationListenerProvider
2326
{

test/Application/BadControllerTrait.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use Laminas\Http\PhpEnvironment\Request;
88
use Laminas\Http\PhpEnvironment\Response;
99
use Laminas\Mvc\Application;
10+
use Laminas\Mvc\ConfigProvider;
1011
use Laminas\Mvc\Controller\ControllerManager;
11-
use Laminas\Router\ConfigProvider;
12+
use Laminas\Router;
1213
use Laminas\Router\Http\Literal;
1314
use Laminas\ServiceManager\ServiceManager;
1415
use Laminas\Stdlib\ArrayUtils;
@@ -21,8 +22,8 @@ trait BadControllerTrait
2122
{
2223
public function prepareApplication(): Application
2324
{
24-
$config = [
25-
'router' => [
25+
$testConfig = [
26+
'router' => [
2627
'routes' => [
2728
'path' => [
2829
'type' => Literal::class,
@@ -36,14 +37,7 @@ public function prepareApplication(): Application
3637
],
3738
],
3839
],
39-
];
40-
41-
$serviceConfig = ArrayUtils::merge(
42-
ArrayUtils::merge(
43-
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
44-
(new ConfigProvider())->getDependencyConfig(),
45-
),
46-
[
40+
'dependencies' => [
4741
'aliases' => [
4842
'ControllerLoader' => ControllerManager::class,
4943
],
@@ -62,13 +56,19 @@ public function prepareApplication(): Application
6256
'SendResponseListener' => MockSendResponseListener::class,
6357
'BootstrapListener' => StubBootstrapListener::class,
6458
],
65-
'services' => [
66-
'config' => $config,
67-
],
68-
]
59+
],
60+
];
61+
62+
$config = ArrayUtils::merge(
63+
ArrayUtils::merge(
64+
(new ConfigProvider())(),
65+
(new Router\ConfigProvider())(),
66+
),
67+
$testConfig
6968
);
70-
$services = new ServiceManager($serviceConfig);
71-
$application = $services->get('Application');
69+
$config['dependencies']['services']['config'] = $config;
70+
$services = new ServiceManager($config['dependencies']);
71+
$application = $services->get('Application');
7272

7373
$request = $services->get('Request');
7474
$request->setUri('http://example.local/bad');

test/Application/InvalidControllerTypeTrait.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use Laminas\Http\PhpEnvironment\Request;
88
use Laminas\Http\PhpEnvironment\Response;
99
use Laminas\Mvc\Application;
10+
use Laminas\Mvc\ConfigProvider;
1011
use Laminas\Mvc\Controller\ControllerManager;
11-
use Laminas\Router\ConfigProvider;
12+
use Laminas\Router;
1213
use Laminas\Router\Http\Literal;
1314
use Laminas\ServiceManager\ServiceManager;
1415
use Laminas\Stdlib\ArrayUtils;
@@ -21,8 +22,8 @@ trait InvalidControllerTypeTrait
2122
{
2223
public function prepareApplication(): Application
2324
{
24-
$config = [
25-
'router' => [
25+
$testConfig = [
26+
'router' => [
2627
'routes' => [
2728
'path' => [
2829
'type' => Literal::class,
@@ -36,14 +37,7 @@ public function prepareApplication(): Application
3637
],
3738
],
3839
],
39-
];
40-
41-
$serviceConfig = ArrayUtils::merge(
42-
ArrayUtils::merge(
43-
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
44-
(new ConfigProvider())->getDependencyConfig(),
45-
),
46-
[
40+
'dependencies' => [
4741
'aliases' => [
4842
'ControllerLoader' => 'ControllerManager',
4943
],
@@ -53,7 +47,6 @@ public function prepareApplication(): Application
5347
'bad' => static fn(): stdClass => new stdClass(),
5448
],
5549
]),
56-
'Router' => static fn($services) => $services->get('HttpRouter'),
5750
],
5851
'invokables' => [
5952
'Request' => Request::class,
@@ -62,13 +55,20 @@ public function prepareApplication(): Application
6255
'SendResponseListener' => MockSendResponseListener::class,
6356
'BootstrapListener' => StubBootstrapListener::class,
6457
],
65-
'services' => [
66-
'config' => $config,
67-
],
68-
]
58+
],
59+
];
60+
61+
$config = ArrayUtils::merge(
62+
ArrayUtils::merge(
63+
(new ConfigProvider())(),
64+
(new Router\ConfigProvider())(),
65+
),
66+
$testConfig
6967
);
70-
$services = new ServiceManager($serviceConfig);
71-
$application = $services->get('Application');
68+
$config['dependencies']['services']['config'] = $config;
69+
70+
$services = new ServiceManager($config['dependencies']);
71+
$application = $services->get('Application');
7272

7373
$request = $services->get('Request');
7474
$request->setUri('http://example.local/bad');

test/Application/MissingControllerTrait.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use Laminas\Http\PhpEnvironment\Request;
88
use Laminas\Http\PhpEnvironment\Response;
99
use Laminas\Mvc\Application;
10-
use Laminas\Router\ConfigProvider;
10+
use Laminas\Mvc\ConfigProvider;
11+
use Laminas\Router;
1112
use Laminas\Router\Http\Literal;
1213
use Laminas\ServiceManager\ServiceManager;
1314
use Laminas\Stdlib\ArrayUtils;
@@ -19,8 +20,8 @@ trait MissingControllerTrait
1920
{
2021
public function prepareApplication(): Application
2122
{
22-
$config = [
23-
'router' => [
23+
$testConfig = [
24+
'router' => [
2425
'routes' => [
2526
'path' => [
2627
'type' => Literal::class,
@@ -34,31 +35,29 @@ public function prepareApplication(): Application
3435
],
3536
],
3637
],
37-
];
38-
39-
$serviceConfig = ArrayUtils::merge(
40-
ArrayUtils::merge(
41-
(new \Laminas\Mvc\ConfigProvider())->getDependencies(),
42-
(new ConfigProvider())->getDependencyConfig(),
43-
),
44-
[
45-
'factories' => [
46-
'Router' => static fn($services) => $services->get('HttpRouter'),
47-
],
38+
'dependencies' => [
4839
'invokables' => [
4940
'Request' => Request::class,
5041
'Response' => Response::class,
5142
'ViewManager' => MockViewManager::class,
5243
'SendResponseListener' => MockSendResponseListener::class,
5344
'BootstrapListener' => StubBootstrapListener::class,
5445
],
55-
'services' => [
56-
'config' => $config,
57-
],
58-
]
46+
],
47+
];
48+
49+
$config = ArrayUtils::merge(
50+
ArrayUtils::merge(
51+
(new ConfigProvider())(),
52+
(new Router\ConfigProvider())(),
53+
),
54+
$testConfig
5955
);
60-
$services = new ServiceManager($serviceConfig);
61-
$application = $services->get('Application');
56+
57+
$config['dependencies']['services']['config'] = $config;
58+
59+
$services = new ServiceManager($config['dependencies']);
60+
$application = $services->get('Application');
6261

6362
$request = $services->get('Request');
6463
$request->setUri('http://example.local/bad');

test/Application/PathControllerTrait.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ trait PathControllerTrait
2222
{
2323
public function prepareApplication(): Application
2424
{
25-
$config = [
26-
'router' => [
25+
$testConfig = [
26+
'router' => [
2727
'routes' => [
2828
'path' => [
2929
'type' => Literal::class,
@@ -36,14 +36,7 @@ public function prepareApplication(): Application
3636
],
3737
],
3838
],
39-
];
40-
41-
$serviceConfig = ArrayUtils::merge(
42-
ArrayUtils::merge(
43-
(new ConfigProvider())->getDependencies(),
44-
(new Router\ConfigProvider())->getDependencyConfig(),
45-
),
46-
[
39+
'dependencies' => [
4740
'aliases' => [
4841
'ControllerLoader' => ControllerManager::class,
4942
],
@@ -53,7 +46,6 @@ public function prepareApplication(): Application
5346
'path' => static fn() => new TestAsset\PathController(),
5447
],
5548
]),
56-
'Router' => static fn($services) => $services->get('HttpRouter'),
5749
],
5850
'invokables' => [
5951
'Request' => Request::class,
@@ -62,13 +54,20 @@ public function prepareApplication(): Application
6254
'SendResponseListener' => MockSendResponseListener::class,
6355
'BootstrapListener' => StubBootstrapListener::class,
6456
],
65-
'services' => [
66-
'config' => $config,
67-
],
68-
]
57+
],
58+
];
59+
60+
$config = ArrayUtils::merge(
61+
ArrayUtils::merge(
62+
(new ConfigProvider())(),
63+
(new Router\ConfigProvider())(),
64+
),
65+
$testConfig
6966
);
70-
$services = new ServiceManager($serviceConfig);
71-
$application = $services->get('Application');
67+
$config['dependencies']['services']['config'] = $config;
68+
69+
$services = new ServiceManager($config['dependencies']);
70+
$application = $services->get('Application');
7271

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

0 commit comments

Comments
 (0)