@@ -59,6 +59,7 @@ public function setUp(): void
5959 #[Test]
6060 #[TestWith([Compression::None, Compression::None])]
6161 #[TestWith([Compression::Gzip, Compression::Gzip])]
62+ #[TestWith([Compression::Bzip2, Compression::Bzip2])]
6263 #[TestWith([Compression::Gzip, 'Gzip ' ])]
6364 #[TestWith([Compression::Gzip, 'gzip ' ])]
6465 #[TestWith([Compression::None, null ])]
@@ -192,12 +193,57 @@ public function runProcess(string $filename, int $timeout = 60): Process
192193 };
193194 $ this ->BackupExport ->Executor ->getEventManager ()->setEventList (new EventList ());
194195
196+ $ result = $ this ->BackupExport ->export ();
197+
198+ $ this ->assertStringStartsWith (Configure::read ('DatabaseBackup.target ' ), $ result );
199+ $ this ->assertMatchesRegularExpression ('/backup_my_database_\d{14}\.sql$/ ' , $ result );
200+ $ this ->assertEventFired ('Backup.beforeExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
201+ $ this ->assertEventFired ('Backup.afterExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
202+ }
203+
204+ /**
205+ * @link \DatabaseBackup\Utility\BackupExport::export()
206+ */
207+ #[Test]
208+ public function testExportWithCompression (): void
209+ {
210+ $ this ->BackupExport ->Executor = new class extends FakeExecutor {
211+ public function runProcess (string $ filename , int $ timeout = 60 ): Process
212+ {
213+ return new ReflectionClass (Process::class)->newInstanceWithoutConstructor ();
214+ }
215+ };
216+ $ this ->BackupExport ->Executor ->getEventManager ()->setEventList (new EventList ());
217+
195218 $ result = $ this ->BackupExport
196- ->filename (TMP . 'backup.sql ' )
197- ->timeout (120 )
219+ ->compression (Compression::Bzip2)
220+ ->export ();
221+
222+ $ this ->assertStringStartsWith (Configure::read ('DatabaseBackup.target ' ), $ result );
223+ $ this ->assertMatchesRegularExpression ('/backup_my_database_\d{14}\.sql\.bz2$/ ' , $ result );
224+ $ this ->assertEventFired ('Backup.beforeExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
225+ $ this ->assertEventFired ('Backup.afterExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
226+ }
227+
228+ /**
229+ * @link \DatabaseBackup\Utility\BackupExport::export()
230+ */
231+ #[Test]
232+ public function testExportWithFilename (): void
233+ {
234+ $ this ->BackupExport ->Executor = new class extends FakeExecutor {
235+ public function runProcess (string $ filename , int $ timeout = 60 ): Process
236+ {
237+ return new ReflectionClass (Process::class)->newInstanceWithoutConstructor ();
238+ }
239+ };
240+ $ this ->BackupExport ->Executor ->getEventManager ()->setEventList (new EventList ());
241+
242+ $ result = $ this ->BackupExport
243+ ->filename (TMP . 'backup.sql.gz ' )
198244 ->export ();
199245
200- $ this ->assertSame (TMP . 'backup.sql ' , $ result );
246+ $ this ->assertSame (TMP . 'backup.sql.gz ' , $ result );
201247 $ this ->assertEventFired ('Backup.beforeExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
202248 $ this ->assertEventFired ('Backup.afterExport ' , $ this ->BackupExport ->Executor ->getEventManager ());
203249 }
0 commit comments