actionHandlerResolver = $this->createPartialMock( HandlerResolver::class, ['getHandlers', 'getValidators'] ); $this->compositeFactory = $this->createPartialMock( CompositeFactory::class, ['create'] ); $this->objectManager = $this->getMockForAbstractClass( ObjectManagerInterface::class ); $this->actionFactory = $objectManager->getObject( ActionFactory::class, [ 'actionHandlerResolver' => $this->actionHandlerResolver, 'compositeFactory' => $this->compositeFactory, 'objectManager' => $this->objectManager, 'dummyHandlerClass' => Dummy::class ] ); } public function testCreate() { $metadata = $this->getMetadataMock(); $loggingAction = $this->createMock(LoggingActionInterface::class); $this->actionHandlerResolver->expects($this->any())->method('getHandlers') ->with(...[self::REQUEST_ACTION_NAME, self::METADATA_EVENT_NAME]) ->willReturn([LoggingActionInterface::class]); $this->objectManager->expects($this->any())->method('create') ->with(...[LoggingActionInterface::class, ['metadata' => $metadata]]) ->willReturn($loggingAction); $this->compositeFactory->expects($this->any())->method('create') ->with(...[['actions' => [$loggingAction]]]) ->willReturn($loggingAction); $result = $this->actionFactory->create($metadata, ActionFactory::FETCH_ANY); $this->assertEquals($result, $loggingAction); } /** * @covers \Amasty\AdminActionsLog\Logging\ActionFactory::create */ public function testCreateNoHandlers() { $metadata = $this->getMetadataMock(); $dummyLoggingAction = $this->createMock(Dummy::class); $this->objectManager->expects($this->any())->method('create') ->with(...[Dummy::class, ['metadata' => $metadata]]) ->willReturn($dummyLoggingAction); $this->compositeFactory->expects($this->any())->method('create') ->with(...[['actions' => [$dummyLoggingAction]]]) ->willReturn($dummyLoggingAction); $result = $this->actionFactory->create($metadata); $this->assertEquals($result, $dummyLoggingAction); } /** * @return Metadata|MockObject */ private function getMetadataMock() { return $this->createConfiguredMock( Metadata::class, [ 'getRequest' => $this->createConfiguredMock( Http::class, ['getFullActionName' => self::REQUEST_ACTION_NAME] ), 'getEventName' => self::METADATA_EVENT_NAME ] ); } }