getMockBuilder(CoreParametersHelper::class) ->disableOriginalConstructor() ->getMock(); $coreParametersHelperMock->expects($this->any()) ->method('get') ->with('report_temp_dir') ->willReturn($tmpDir); $filePathResolver = $this->getMockBuilder(FilePathResolver::class) ->disableOriginalConstructor() ->getMock(); $filePathResolver->expects($this->once()) ->method('createDirectory'); $exportHandler = new ExportHandler($coreParametersHelperMock, $filePathResolver); $handler = $exportHandler->getHandler('myFile'); $this->assertIsResource($handler); $exportHandler->closeHandler($handler); $this->assertIsClosedResource($handler); } public function testCreateDirectoryError(): void { $tmpDir = sys_get_temp_dir(); $this->expectException(FileIOException::class); $this->expectExceptionMessage('Could not create directory '.$tmpDir); $coreParametersHelperMock = $this->getMockBuilder(CoreParametersHelper::class) ->disableOriginalConstructor() ->getMock(); $coreParametersHelperMock->expects($this->any()) ->method('get') ->with('report_temp_dir') ->willReturn($tmpDir); $filePathResolver = $this->getMockBuilder(FilePathResolver::class) ->disableOriginalConstructor() ->getMock(); $filePathResolver->expects($this->once()) ->method('createDirectory') ->willThrowException(new FilePathException()); $exportHandler = new ExportHandler($coreParametersHelperMock, $filePathResolver); $exportHandler->getHandler('myFile'); } public function testOpenFileError(): void { $tmpDir = 'xxx'; $this->expectException(FileIOException::class); $this->expectExceptionMessage('Could not open file xxx/myFile.csv'); $coreParametersHelperMock = $this->getMockBuilder(CoreParametersHelper::class) ->disableOriginalConstructor() ->getMock(); $coreParametersHelperMock->expects($this->any()) ->method('get') ->with('report_temp_dir') ->willReturn($tmpDir); $filePathResolver = $this->getMockBuilder(FilePathResolver::class) ->disableOriginalConstructor() ->getMock(); $filePathResolver->expects($this->once()) ->method('createDirectory'); $exportHandler = new ExportHandler($coreParametersHelperMock, $filePathResolver); $exportHandler->getHandler('myFile'); } }