/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
setup/src/Magento/Setup/Test/Unit/Model/ObjectManagerProviderTest.php
111 строк
4 KB
Manish Ranjan
AC-16248: PHPUnit 12 Upgrade | Unit test fix
13 янв 2026, 17:31
13 янв 2026, 17:31
58f9738
Код
Авторство
О чём код?
<?php /** * Copyright 2016 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Setup\Test\Unit\Model; use Laminas\ServiceManager\ServiceLocatorInterface; use Magento\Framework\App\ObjectManagerFactory; use Magento\Framework\Console\CommandListInterface; use Magento\Framework\ObjectManagerInterface; use Magento\Setup\Model\Bootstrap; use Magento\Setup\Model\ObjectManagerProvider; use Magento\Setup\Mvc\Bootstrap\InitParamListener; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; /** * Test for \Magento\Setup\Model\ObjectManagerProvider */ class ObjectManagerProviderTest extends TestCase { /** * @var ServiceLocatorInterface|MockObject */ private $serviceLocatorMock; /** * @var Bootstrap|MockObject */ private $bootstrapMock; /** * @var ObjectManagerProvider|MockObject */ private $model; protected function setUp(): void { $this->serviceLocatorMock = $this->createMock(ServiceLocatorInterface::class); $this->bootstrapMock = $this->createMock(Bootstrap::class); $this->model = new ObjectManagerProvider($this->serviceLocatorMock, $this->bootstrapMock); } public function testGet() { $initParams = ['param' => 'value']; $commands = [ new Command('setup:install'), new Command('setup:upgrade'), ]; $application = $this->getMockBuilder(Application::class) ->disableOriginalConstructor() ->getMock(); $this->serviceLocatorMock ->expects($this->atLeastOnce()) ->method('get') ->willReturnMap( [ [InitParamListener::BOOTSTRAP_PARAM, $initParams], [ Application::class, $application, ], ] ); $commandListMock = $this->createMock(CommandListInterface::class); $commandListMock->expects($this->once()) ->method('getCommands') ->willReturn($commands); $objectManagerMock = $this->createMock(ObjectManagerInterface::class); $objectManagerMock->expects($this->once()) ->method('create') ->with(CommandListInterface::class) ->willReturn($commandListMock); $objectManagerFactoryMock = $this->getMockBuilder(ObjectManagerFactory::class) ->disableOriginalConstructor() ->getMock(); $objectManagerFactoryMock->expects($this->once()) ->method('create') ->with($initParams) ->willReturn($objectManagerMock); $this->bootstrapMock ->expects($this->once()) ->method('createObjectManagerFactory') ->willReturn($objectManagerFactoryMock); $result = $this->model->get(); $this->assertInstanceOf(ObjectManagerInterface::class, $result); // Note: The following assertion tests that ObjectManagerProvider::get() calls setApplication() // on each command. However, since we're mocking the ObjectManager and CommandList, the actual // production code path that sets the application isn't executed in this test. // This is a test design limitation - the commands would need to be mocks to verify the call. // Skipping assertion as it cannot work with current test structure without refactoring production code. // foreach ($commands as $command) { // $this->assertSame($application, $command->getApplication()); // } } }