createMock(FormBuilderInterface::class); $formBuilder = $this->createMock(FormBuilderInterface::class); $formBuilder->method('create')->willReturn($expectedResult); $formClassNameService = $this->createMock(FormClassNameServiceInterface::class); $formClassNameService->method('getClass')->willReturn('dummyNamespace'); $entityFormBuilderService = new RequestedEntityFormBuilderService($formBuilder, $formClassNameService); $entity = new PureSource(); $entityRequested = $this->createMock(RequestedEntityInterface::class); $entityRequested->method('hasIdentity')->willReturn(true); $entityRequested->method('getEntity')->willReturn($entity); $result = $entityFormBuilderService->create($entityRequested); $this->assertEquals($expectedResult, $result); } }