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']; $this->serviceLocatorMock ->expects($this->atLeastOnce()) ->method('get') ->willReturnMap( [ [InitParamListener::BOOTSTRAP_PARAM, $initParams], [ Application::class, $this->getMockBuilder(Application::class)->disableOriginalConstructor()->getMock(), ], ] ); $objectManagerMock = $this->createMock(ObjectManagerInterface::class); $objectManagerMock->expects($this->once()) ->method('create') ->with(CommandListInterface::class) ->willReturn($this->getCommandListMock()); $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); $this->assertInstanceOf(ObjectManagerInterface::class, $this->model->get()); } /** * @return \PHPUnit_Framework_MockObject_MockObject */ private function getCommandListMock() { $commandMock = $this->getMockBuilder(Command::class)->disableOriginalConstructor()->getMock(); $commandMock->expects($this->once())->method('setApplication'); $commandListMock = $this->createMock(CommandListInterface::class); $commandListMock->expects($this->once()) ->method('getCommands') ->willReturn([$commandMock]); return $commandListMock; } }