tempFilePath = '/tmp/' . uniqid(); file_put_contents($this->tempFilePath, ''); } public function tearDown(): void { @unlink($this->tempFilePath); } public function testStoreSharedStimulus(): void { $fakeUniqueName = 'uniqueString'; $fileSystemMock = $this->initFileSystemMock(); $fileSystemMock->expects(self::once()) ->method('createDir') ->with($fakeUniqueName); $fileSystemMock->expects(self::once()) ->method('writeStream') ->willReturn(true); $stimulusStoreService = $this->getPreparedServiceInstance($fileSystemMock); $stimulusStoreService->expects(self::once()) ->method('getUniqueName') ->willReturn($fakeUniqueName); $result = $stimulusStoreService->store($this->tempFilePath, 'dummyString', []); $this->assertEquals($result, $fakeUniqueName); } /** * @return FileSystem|MockObject */ private function initFileSystemMock(): FileSystem { return $this->getMockBuilder(FileSystem::class) ->disableOriginalConstructor() ->onlyMethods(['createDir', 'writeStream']) ->getMock(); } /** * @return StoreService|MockObject */ private function getPreparedServiceInstance(FileSystem $fileSystemMock): StoreService { $fileSystemServiceProphecy = $this->prophesize(FileSystemService::class); $fileSystemServiceProphecy->getFileSystem(Argument::any())->willReturn($fileSystemMock); $service = $this->getMockBuilder(StoreService::class)->onlyMethods(['getUniqueName'])->getMock(); $service->setServiceLocator( $this->getServiceLocatorMock( [ FlySystemManagement::SERVICE_ID => $this->getMockBuilder(FlySystemManagement::class)->getMock(), FileSystemService::SERVICE_ID => $fileSystemServiceProphecy->reveal() ] ) ); return $service; } }