Skip to content

Commit 2eebb7f

Browse files
committed
Refine ExportCommandTest by removing unused import, adding @link annotation, and enhancing mock usage for better readability and maintainability
1 parent 0f3f5e9 commit 2eebb7f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tests/TestCase/Command/ExportCommandTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace DatabaseBackup\Test\TestCase\Command;
1717

1818
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
19-
use Cake\Console\TestSuite\StubConsoleOutput;
2019
use Cake\Core\Configure;
2120
use DatabaseBackup\Command\ExportCommand;
2221
use DatabaseBackup\TestSuite\TestCase;
@@ -36,6 +35,9 @@ class ExportCommandTest extends TestCase
3635
{
3736
use ConsoleIntegrationTestTrait;
3837

38+
/**
39+
* @link \DatabaseBackup\Command\ExportCommand::buildOptionParser()
40+
*/
3941
#[Test]
4042
#[RequiresOperatingSystemFamily('Linux')]
4143
public function testBuildOptionParser(): void
@@ -134,8 +136,10 @@ public function testExecuteWithCompressionOption(): void
134136
#[RunInSeparateProcess]
135137
public function testExecuteOnException(): void
136138
{
137-
$BackupExport = Mockery::mock('overload:' . BackupExport::class);
138-
$BackupExport->shouldReceive('export')->once()->andThrow(new Exception('Exception message'));
139+
Mockery::mock('overload:' . BackupExport::class)
140+
->shouldReceive('export')
141+
->once()
142+
->andThrow(new Exception('Exception message'));
139143

140144
$this->exec('database_backup.export');
141145
$this->assertExitError();
@@ -146,11 +150,12 @@ public function testExecuteOnException(): void
146150
#[RunInSeparateProcess]
147151
public function testExecuteOnStoppedEvent(): void
148152
{
149-
$BackupExport = Mockery::mock('overload:' . BackupExport::class);
150-
$BackupExport->shouldReceive('export')->once()->andReturnFalse();
153+
Mockery::mock('overload:' . BackupExport::class)
154+
->shouldReceive('export')
155+
->once()
156+
->andReturnFalse();
151157

152158
$this->exec('database_backup.export');
153-
154159
$this->assertExitError();
155160
$this->assertErrorContains('<error>The `Backup.beforeExport` event stopped the operation</error>');
156161
}

0 commit comments

Comments
 (0)