Skip to content

Commit 2e0d792

Browse files
committed
AC-15068::Laminas MVC Retiring
1 parent f006a5a commit 2e0d792

11 files changed

+347
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\EventManager\EventManager;
11+
use Laminas\ServiceManager\ServiceManager;
12+
use Magento\Framework\Setup\Mvc\ModuleManager;
13+
use Magento\Framework\Setup\Mvc\ModuleManagerFactory;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class ModuleManagerFactoryTest extends TestCase
17+
{
18+
public function testFactoryCreatesModuleManagerWithConfigModulesAndEventManager(): void
19+
{
20+
$sm = new ServiceManager();
21+
$sm->setService('ApplicationConfig', [
22+
'modules' => ['Foo\\Bar'],
23+
]);
24+
$sm->setService('EventManager', new EventManager());
25+
26+
$factory = new ModuleManagerFactory();
27+
$instance = $factory($sm, 'ModuleManager');
28+
29+
$this->assertInstanceOf(ModuleManager::class, $instance);
30+
}
31+
}
32+
33+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\EventManager\EventManager;
11+
use Magento\Framework\Setup\Mvc\ModuleManager;
12+
use Magento\Framework\Setup\Mvc\TestModule;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ModuleManagerTest extends TestCase
16+
{
17+
public function testLoadModulesMergesConfigAndTriggersEvent(): void
18+
{
19+
// Prefer a class that matches the Module naming convention <Namespace>\Module
20+
require_once dirname(__DIR__) . '/_files/FixtureModule.php';
21+
22+
$modules = [
23+
// Base namespace; ModuleManager will append "\\Module"
24+
__NAMESPACE__ . '\\Fixture',
25+
__NAMESPACE__ . '\\NoSuchModule',
26+
];
27+
28+
$eventManager = new EventManager();
29+
$triggered = false;
30+
$captured = [];
31+
$eventManager->attach('loadModules.post', function ($e) use (&$triggered, &$captured) {
32+
$triggered = true;
33+
$captured = $e->getParams();
34+
});
35+
36+
$mm = new ModuleManager($modules, $eventManager);
37+
$mm->loadModules();
38+
39+
$this->assertTrue($triggered, 'Expected loadModules.post to be triggered');
40+
$this->assertArrayHasKey('config', $captured);
41+
$this->assertSame('bar', $captured['config']['service_manager']['services']['foo'] ?? null);
42+
}
43+
}
44+
45+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\ServiceManager\ServiceManager;
11+
use Magento\Framework\Setup\Mvc\MvcApplication;
12+
use Magento\Framework\Setup\Mvc\TestBootstrapListener;
13+
use Magento\Framework\Setup\Mvc\TestModule;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class MvcApplicationTest extends TestCase
17+
{
18+
public function testInitBootstrapsServiceManagerAndLoadsModules(): void
19+
{
20+
$config = [
21+
'modules' => [
22+
__NAMESPACE__ . '\\Fixture\\Module',
23+
],
24+
'service_manager' => [
25+
'services' => [
26+
'foo' => 'bar',
27+
],
28+
],
29+
'module_listener_options' => [
30+
'config_glob_paths' => [],
31+
],
32+
'listeners' => [],
33+
];
34+
35+
require_once dirname(__DIR__) . '/_files/FixtureModule.php';
36+
37+
$app = MvcApplication::init($config);
38+
39+
$this->assertInstanceOf(MvcApplication::class, $app);
40+
$sm = $app->getServiceManager();
41+
$this->assertInstanceOf(ServiceManager::class, $sm);
42+
$this->assertSame('bar', $sm->get('foo'));
43+
$this->assertIsArray($app->getConfig());
44+
}
45+
46+
public function testBootstrapInvokesListeners(): void
47+
{
48+
$config = [
49+
'modules' => [],
50+
'service_manager' => [
51+
'services' => [],
52+
'factories' => [],
53+
],
54+
'module_listener_options' => [
55+
'config_glob_paths' => [],
56+
],
57+
'listeners' => [],
58+
];
59+
60+
$app = MvcApplication::init($config);
61+
62+
require_once dirname(__DIR__) . '/_files/TestBootstrapListener.php';
63+
64+
$sm = $app->getServiceManager();
65+
$sm->setService(TestBootstrapListener::class, new TestBootstrapListener());
66+
67+
$app->bootstrap([TestBootstrapListener::class]);
68+
69+
$this->assertTrue(TestBootstrapListener::$bootstrapped);
70+
}
71+
}
72+
73+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\ServiceManager\ServiceManager;
11+
use Magento\Framework\Setup\Mvc\MvcApplication;
12+
use Magento\Framework\Setup\Mvc\MvcEvent;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class MvcEventTest extends TestCase
16+
{
17+
public function testSetGetApplication(): void
18+
{
19+
$sm = new ServiceManager();
20+
$app = new MvcApplication($sm);
21+
$event = new MvcEvent();
22+
$event->setApplication($app);
23+
$this->assertSame($app, $event->getApplication());
24+
}
25+
}
26+
27+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\EventManager\EventManager;
11+
use Laminas\ServiceManager\ServiceManager;
12+
use Magento\Framework\Setup\Mvc\MvcServiceManagerConfig;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class MvcServiceManagerConfigTest extends TestCase
16+
{
17+
public function testConfigureServiceManagerSetsAliasesFactoriesAndInitializer(): void
18+
{
19+
$config = new MvcServiceManagerConfig([
20+
'services' => [ 'x' => 1 ],
21+
]);
22+
$sm = new ServiceManager();
23+
24+
$config->configureServiceManager($sm);
25+
26+
// Core services
27+
$this->assertSame($sm, $sm->get(ServiceManager::class));
28+
$this->assertInstanceOf(EventManager::class, $sm->get('EventManager'));
29+
30+
// Aliases
31+
$this->assertTrue($sm->has('SharedEventManager'));
32+
33+
// Factories
34+
$this->assertTrue($sm->has('ServiceListener'));
35+
$this->assertTrue($sm->has('ModuleManager'));
36+
}
37+
38+
public function testToArrayReturnsConfig(): void
39+
{
40+
$cfg = new MvcServiceManagerConfig();
41+
$this->assertIsArray($cfg->toArray());
42+
$this->assertArrayHasKey('aliases', $cfg->toArray());
43+
}
44+
}
45+
46+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\ModuleManager\Listener\ServiceListener;
11+
use Laminas\ServiceManager\ServiceManager;
12+
use Magento\Framework\Setup\Mvc\ServiceListenerFactory;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ServiceListenerFactoryTest extends TestCase
16+
{
17+
public function testFactoryReturnsServiceListener(): void
18+
{
19+
$sm = new ServiceManager();
20+
$factory = new ServiceListenerFactory();
21+
$listener = $factory($sm, 'ServiceListener');
22+
$this->assertInstanceOf(ServiceListener::class, $listener);
23+
}
24+
}
25+
26+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Test\Unit\Mvc;
9+
10+
use Laminas\ServiceManager\ServiceManager;
11+
use Magento\Framework\Setup\Mvc\ServiceManagerFactory;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class ServiceManagerFactoryTest extends TestCase
15+
{
16+
public function testGetHasBuildDelegatesToUnderlyingServiceManager(): void
17+
{
18+
$laminasSm = new ServiceManager([
19+
'services' => [
20+
'alpha' => 'a',
21+
],
22+
'factories' => [
23+
'beta' => function () {
24+
return 'b';
25+
},
26+
],
27+
]);
28+
29+
ServiceManagerFactory::setServiceManager($laminasSm);
30+
$bridge = new ServiceManagerFactory();
31+
32+
$this->assertTrue($bridge->has('alpha'));
33+
$this->assertSame('a', $bridge->get('alpha'));
34+
$this->assertSame('b', $bridge->build('beta'));
35+
}
36+
}
37+
38+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\Framework\Setup\Test\Unit\Mvc\Fixture;
5+
6+
final class Module
7+
{
8+
public function getConfig(): array
9+
{
10+
return [
11+
'service_manager' => [
12+
'services' => [
13+
'foo' => 'bar',
14+
],
15+
],
16+
];
17+
}
18+
}
19+
20+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\Framework\Setup\Mvc;
5+
6+
use Magento\Framework\Setup\Mvc\MvcApplication;
7+
use Magento\Framework\Setup\Mvc\MvcEvent;
8+
9+
final class TestBootstrapListener
10+
{
11+
public static bool $bootstrapped = false;
12+
13+
public function onBootstrap(MvcEvent $event): void
14+
{
15+
self::$bootstrapped = $event->getApplication() instanceof MvcApplication;
16+
}
17+
}
18+
19+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\Framework\Setup\Mvc;
5+
6+
final class TestModule
7+
{
8+
public function getConfig(): array
9+
{
10+
return [
11+
'service_manager' => [
12+
'services' => [
13+
'foo' => 'bar',
14+
],
15+
],
16+
];
17+
}
18+
}
19+
20+

0 commit comments

Comments
 (0)