Skip to content

Commit 707b39d

Browse files
committed
Refactor BackupExportTest to enhance mock reuse and improve test structure for export() method variants
1 parent e7fc584 commit 707b39d

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

tests/TestCase/Utility/BackupExportTest.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
use ValueError;
3737

3838
/**
39-
* BackupExportTest
39+
* BackupExportTest.
4040
*/
4141
#[CoversClass(BackupExport::class)]
4242
class BackupExportTest extends TestCase
@@ -51,6 +51,15 @@ public function setUp(): void
5151
parent::setUp();
5252

5353
$this->BackupExport = new BackupExport(Connection: new FakeConnection());
54+
55+
$this->BackupExport->Executor = new class extends FakeExecutor {
56+
public function runProcess(string $filename, int $timeout = 60): Process
57+
{
58+
return new ReflectionClass(Process::class)->newInstanceWithoutConstructor();
59+
}
60+
};
61+
62+
$this->BackupExport->Executor->getEventManager()->setEventList(new EventList());
5463
}
5564

5665
/**
@@ -180,19 +189,13 @@ public function testCallMagicMethod(): void
180189
}
181190

182191
/**
192+
* Tests for the `export()` method, without calls to the `filename()` and `compression()` methods.
193+
*
183194
* @link \DatabaseBackup\Utility\BackupExport::export()
184195
*/
185196
#[Test]
186197
public function testExport(): void
187198
{
188-
$this->BackupExport->Executor = new class extends FakeExecutor {
189-
public function runProcess(string $filename, int $timeout = 60): Process
190-
{
191-
return new ReflectionClass(Process::class)->newInstanceWithoutConstructor();
192-
}
193-
};
194-
$this->BackupExport->Executor->getEventManager()->setEventList(new EventList());
195-
196199
$result = $this->BackupExport->export();
197200

198201
$this->assertStringStartsWith(Configure::read('DatabaseBackup.target'), $result);
@@ -202,19 +205,13 @@ public function runProcess(string $filename, int $timeout = 60): Process
202205
}
203206

204207
/**
208+
* Tests for the `export()` method, with a call to the `compression()` method.
209+
*
205210
* @link \DatabaseBackup\Utility\BackupExport::export()
206211
*/
207212
#[Test]
208213
public function testExportWithCompression(): void
209214
{
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-
218215
$result = $this->BackupExport
219216
->compression(Compression::Bzip2)
220217
->export();
@@ -226,19 +223,13 @@ public function runProcess(string $filename, int $timeout = 60): Process
226223
}
227224

228225
/**
226+
* Tests for the `export()` method, with a call to the `filename()` method.
227+
*
229228
* @link \DatabaseBackup\Utility\BackupExport::export()
230229
*/
231230
#[Test]
232231
public function testExportWithFilename(): void
233232
{
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-
242233
$result = $this->BackupExport
243234
->filename(TMP . 'backup.sql.gz')
244235
->export();
@@ -273,6 +264,7 @@ public function testExportWithTimeoutFromConfiguration(): void
273264
}
274265

275266
/**
267+
* Tests for the `export()` method.
276268
* `export()` is stopped by the `Backup.beforeExport` event (implemented by the `Executor` class).
277269
*
278270
* @link \DatabaseBackup\Utility\BackupExport::export()

0 commit comments

Comments
 (0)