transferBuilder = $this->createMock(TransferBuilder::class); $this->transferMock = $this->createMock(TransferInterface::class); $this->transferFactory = new TransferFactory( $this->transferBuilder ); } public function testCreate() { $request = ['data1', 'data2']; $this->transferBuilder->expects($this->once()) ->method('setBody') ->with($request) ->willReturnSelf(); $this->transferBuilder->expects($this->once()) ->method('build') ->willReturn($this->transferMock); $this->assertEquals($this->transferMock, $this->transferFactory->create($request)); } }