24 private $filesystemMock;
34 private $reportWriterMock;
39 private $cryptographerMock;
44 private $fileRecorderMock;
49 private $directoryMock;
54 private $encodedContextMock;
59 private $objectManagerHelper;
64 private $exportDataHandler;
69 private $subdirectoryPath =
'analytics/';
74 private $archiveName =
'data.tgz';
81 $this->filesystemMock = $this->getMockBuilder(Filesystem::class)
82 ->disableOriginalConstructor()
85 $this->archiveMock = $this->getMockBuilder(Archive::class)
86 ->disableOriginalConstructor()
89 $this->reportWriterMock = $this->getMockBuilder(ReportWriterInterface::class)
90 ->disableOriginalConstructor()
93 $this->cryptographerMock = $this->getMockBuilder(Cryptographer::class)
94 ->disableOriginalConstructor()
97 $this->fileRecorderMock = $this->getMockBuilder(FileRecorder::class)
98 ->disableOriginalConstructor()
101 $this->directoryMock = $this->getMockBuilder(WriteInterface::class)
102 ->disableOriginalConstructor()
105 $this->encodedContextMock = $this->getMockBuilder(EncodedContext::class)
106 ->disableOriginalConstructor()
109 $this->objectManagerHelper =
new ObjectManagerHelper($this);
111 $this->exportDataHandler = $this->objectManagerHelper->getObject(
112 ExportDataHandler::class,
114 'filesystem' => $this->filesystemMock,
115 'archive' => $this->archiveMock,
116 'reportWriter' => $this->reportWriterMock,
117 'cryptographer' => $this->cryptographerMock,
118 'fileRecorder' => $this->fileRecorderMock,
119 'subdirectoryPath' => $this->subdirectoryPath,
120 'archiveName' => $this->archiveName,
131 $tmpFilesDirectoryPath = $this->subdirectoryPath .
'tmp/';
132 $archiveRelativePath = $this->subdirectoryPath . $this->archiveName;
134 $archiveSource = $isArchiveSourceDirectory ? (
__DIR__) :
'/tmp/' . $tmpFilesDirectoryPath;
135 $archiveAbsolutePath =
'/tmp/' . $archiveRelativePath;
137 $this->filesystemMock
138 ->expects($this->once())
139 ->method(
'getDirectoryWrite')
141 ->willReturn($this->directoryMock);
143 ->expects($this->exactly(4))
146 [$tmpFilesDirectoryPath],
147 [$archiveRelativePath]
151 ->expects($this->exactly(4))
152 ->method(
'getAbsolutePath')
154 [$tmpFilesDirectoryPath],
155 [$tmpFilesDirectoryPath],
156 [$archiveRelativePath],
157 [$archiveRelativePath]
159 ->willReturnOnConsecutiveCalls(
162 $archiveAbsolutePath,
166 $this->reportWriterMock
167 ->expects($this->once())
169 ->with($this->directoryMock, $tmpFilesDirectoryPath);
172 ->expects($this->exactly(2))
175 [$tmpFilesDirectoryPath],
176 [$archiveRelativePath]
178 ->willReturnOnConsecutiveCalls(
184 ->expects($this->once())
186 ->with(dirname($archiveRelativePath));
189 ->expects($this->once())
193 $archiveAbsolutePath,
194 $isArchiveSourceDirectory ?
true :
false 197 $fileContent =
'Some text';
199 ->expects($this->once())
201 ->with($archiveRelativePath)
202 ->willReturn($fileContent);
204 $this->cryptographerMock
205 ->expects($this->once())
208 ->willReturn($this->encodedContextMock);
210 $this->fileRecorderMock
211 ->expects($this->once())
212 ->method(
'recordNewFile')
213 ->with($this->encodedContextMock);
215 $this->assertTrue($this->exportDataHandler->prepareExportData());
224 'Data source for archive is directory' => [
true],
225 'Data source for archive doesn\'t directory' => [
false],
235 $tmpFilesDirectoryPath = $this->subdirectoryPath .
'tmp/';
236 $archivePath = $this->subdirectoryPath . $this->archiveName;
238 $this->filesystemMock
239 ->expects($this->once())
240 ->method(
'getDirectoryWrite')
242 ->willReturn($this->directoryMock);
243 $this->reportWriterMock
244 ->expects($this->once())
246 ->with($this->directoryMock, $tmpFilesDirectoryPath);
248 ->expects($this->exactly(3))
251 [$tmpFilesDirectoryPath],
252 [$tmpFilesDirectoryPath],
256 ->expects($this->exactly(2))
257 ->method(
'getAbsolutePath')
258 ->with($tmpFilesDirectoryPath);
260 ->expects($this->once())
262 ->with($tmpFilesDirectoryPath)
265 $this->assertNull($this->exportDataHandler->prepareExportData());
testPrepareExportData($isArchiveSourceDirectory)
prepareExportDataDataProvider()
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testPrepareExportDataWithLocalizedException()