Skip to content

Commit 027edd1

Browse files
committed
Add @link annotations and improve test case structure for Executor classes
Includes adjustments to method names, exception messages, and `DataProvider` consistency for enhanced readability and maintainability.
1 parent 7506cff commit 027edd1

File tree

4 files changed

+80
-16
lines changed

4 files changed

+80
-16
lines changed

tests/TestCase/Executor/ExecutorTest.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,32 @@
3737
#[CoversClass(Executor::class)]
3838
class ExecutorTest extends TestCase
3939
{
40+
/**
41+
* @link \DatabaseBackup\Executor\Executor::implementedEvents()
42+
*/
4043
#[Test]
4144
public function testImplementedEvents(): void
4245
{
46+
$expected = [
47+
'Backup.afterExport' => 'afterExport',
48+
'Backup.afterImport' => 'afterImport',
49+
'Backup.beforeExport' => 'beforeExport',
50+
'Backup.beforeImport' => 'beforeImport',
51+
];
4352
$result = new FakeExecutor()->implementedEvents();
4453

45-
$this->assertContains('beforeExport', $result);
46-
$this->assertContains('afterExport', $result);
47-
$this->assertContains('beforeImport', $result);
48-
$this->assertContains('afterImport', $result);
54+
$this->assertSame($expected, $result);
4955
}
5056

57+
/**
58+
* @link \DatabaseBackup\Executor\Executor::findBinary()
59+
*/
5160
#[Test]
5261
#[TestWith(['/usr/bin/mariadb', 'mariadb'])]
5362
#[TestWith(['/usr/bin/mysql', 'mysql'])]
5463
#[TestWith(['/usr/bin/gzip', Compression::Gzip])]
5564
#[RunInSeparateProcess]
56-
public function testFindBinary(string $expectedBinary, string|Compression $name): void
65+
public function testFindBinary(string $expectedBinary, Compression|string $name): void
5766
{
5867
Mockery::spy('overload:Symfony\Component\Process\ExecutableFinder')
5968
->shouldReceive('find')
@@ -65,11 +74,14 @@ public function testFindBinary(string $expectedBinary, string|Compression $name)
6574
$this->assertSame($expectedBinary, $result);
6675
}
6776

77+
/**
78+
* @link \DatabaseBackup\Executor\Executor::findBinary()
79+
*/
6880
#[Test]
6981
#[TestWith(['/customPath/mariadb', 'mariadb'])]
7082
#[TestWith(['/customPath/mysql', 'mysql'])]
7183
#[TestWith(['/customPath/gzip', Compression::Gzip])]
72-
public function testFindBinaryFromConfiguration(string $expectedBinary, string|Compression $binaryName): void
84+
public function testFindBinaryFromConfiguration(string $expectedBinary, Compression|string $binaryName): void
7385
{
7486
$binaryName = $binaryName instanceof Compression ? lcfirst($binaryName->name) : $binaryName;
7587
Configure::write(config: 'DatabaseBackup.binaries.' . $binaryName, value: '/customPath/' . $binaryName);
@@ -80,17 +92,22 @@ public function testFindBinaryFromConfiguration(string $expectedBinary, string|C
8092
$this->assertSame($expectedBinary, $result);
8193
}
8294

95+
/**
96+
* @link \DatabaseBackup\Executor\Executor::findBinary()
97+
*/
8398
#[Test]
8499
public function testFindBinaryWithNoExistingBinary(): void
85100
{
86101
$this->expectException(InvalidArgumentException::class);
87-
$this->expectExceptionMessage(sprintf(
88-
'Binary for `noExisting` not found. Set path manually: `%s`',
89-
'Configure::write(\'DatabaseBackup.binaries.noExisting\', \'/path/to/noExisting\')'
90-
));
102+
$this->expectExceptionMessage(
103+
'Binary for `noExisting` not found. Set path manually: `Configure::write(\'DatabaseBackup.binaries.noExisting\', \'/path/to/noExisting\')`',
104+
);
91105
new FakeExecutor()->findBinary('noExisting');
92106
}
93107

108+
/**
109+
* @link \DatabaseBackup\Executor\Executor::findBinary()
110+
*/
94111
#[Test]
95112
public function testFindBinaryWithCompressionNone(): void
96113
{
@@ -99,6 +116,9 @@ public function testFindBinaryWithCompressionNone(): void
99116
new FakeExecutor()->findBinary(Compression::None);
100117
}
101118

119+
/**
120+
* @link \DatabaseBackup\Executor\Executor::getCommand()
121+
*/
102122
#[Test]
103123
#[TestWith(['"${:BINARY}" "${:DB_NAME}" .dump > "${:FILENAME}"', OperationType::Export, Compression::None])]
104124
#[TestWith(['"${:BINARY}" "${:DB_NAME}" .dump | "${:COMPRESSION_BINARY}" > "${:FILENAME}"', OperationType::Export, Compression::Gzip])]
@@ -113,6 +133,9 @@ public function testGetCommand(string $expectedCommand, OperationType $Operation
113133
$this->assertSame($expectedCommand, $result);
114134
}
115135

136+
/**
137+
* @link \DatabaseBackup\Executor\Executor::runProcess()
138+
*/
116139
#[Test]
117140
#[TestWith(['"${:BINARY}" "${:DB_NAME}" .dump > "${:FILENAME}"', 'filename.sql', OperationType::Export])]
118141
#[TestWith(['"${:BINARY}" "${:DB_NAME}" .dump | "${:COMPRESSION_BINARY}" > "${:FILENAME}"', 'filename.sql.gz', OperationType::Export])]
@@ -202,6 +225,9 @@ public function testRunProcess(string $expectedCommand, string $filename, Operat
202225
$this->assertSame($Process, $result);
203226
}
204227

228+
/**
229+
* @link \DatabaseBackup\Executor\Executor::runProcess()
230+
*/
205231
#[Test]
206232
#[RunInSeparateProcess]
207233
public function testRunProcessOnFailure(): void

tests/TestCase/Executor/MysqlExecutorTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,21 @@ public function setUp(): void
4444
$this->MysqlExecutor = new MysqlExecutor(Connection: new FakeConnection(), OperationType: OperationType::Export);
4545
}
4646

47+
/**
48+
* @link \DatabaseBackup\Executor\MysqlExecutor::getBinaryName()
49+
*/
4750
#[Test]
4851
#[TestWith(['mariadb-dump', OperationType::Export])]
4952
#[TestWith(['mariadb', OperationType::Import])]
50-
public function testGetBinaryName(string $expectedBinarName, OperationType $OperationType): void
53+
public function testGetBinaryName(string $expectedBinaryName, OperationType $OperationType): void
5154
{
5255
$MysqlExecutor = new MysqlExecutor(Connection: new FakeConnection(), OperationType: $OperationType);
53-
$this->assertSame($expectedBinarName, $MysqlExecutor->getBinaryName());
56+
$this->assertSame($expectedBinaryName, $MysqlExecutor->getBinaryName());
5457
}
5558

59+
/**
60+
* @link \DatabaseBackup\Executor\MysqlExecutor::afterExport()
61+
*/
5662
#[Test]
5763
public function testAfterExport(): void
5864
{
@@ -66,6 +72,9 @@ public function testAfterExport(): void
6672
->once();
6773
}
6874

75+
/**
76+
* @link \DatabaseBackup\Executor\MysqlExecutor::afterImport()
77+
*/
6978
#[Test]
7079
public function testAfterImport(): void
7180
{
@@ -79,6 +88,9 @@ public function testAfterImport(): void
7988
->once();
8089
}
8190

91+
/**
92+
* @link \DatabaseBackup\Executor\MysqlExecutor::beforeExport()
93+
*/
8294
#[Test]
8395
public function testBeforeExport(): void
8496
{
@@ -95,6 +107,9 @@ public function testBeforeExport(): void
95107
->once();
96108
}
97109

110+
/**
111+
* @link \DatabaseBackup\Executor\MysqlExecutor::beforeImport()
112+
*/
98113
#[Test]
99114
public function testBeforeImport(): void
100115
{
@@ -111,6 +126,9 @@ public function testBeforeImport(): void
111126
->once();
112127
}
113128

129+
/**
130+
* @link \DatabaseBackup\Executor\MysqlExecutor::writeAuthFile()
131+
*/
114132
#[Test]
115133
#[RunInSeparateProcess]
116134
public function testWriteAuthFile(): void
@@ -142,6 +160,9 @@ public function testWriteAuthFile(): void
142160
$this->assertTrue($result);
143161
}
144162

163+
/**
164+
* @link \DatabaseBackup\Executor\MysqlExecutor::deleteAuthFile()
165+
*/
145166
#[Test]
146167
#[RunInSeparateProcess]
147168
public function testDeleteAuthFile(): void

tests/TestCase/Executor/PostgresExecutorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
#[CoversClass(PostgresExecutor::class)]
3030
class PostgresExecutorTest extends TestCase
3131
{
32+
/**
33+
* @link \DatabaseBackup\Executor\PostgresExecutor::getBinaryName()
34+
*/
3235
#[Test]
3336
#[TestWith(['pg_dump', OperationType::Export])]
3437
#[TestWith(['pg_restore', OperationType::Import])]
35-
public function testGetBinaryName(string $expectedBinarName, OperationType $OperationType): void
38+
public function testGetBinaryName(string $expectedBinaryName, OperationType $OperationType): void
3639
{
3740
$PostgresExecutor = new PostgresExecutor(Connection: new FakeConnection(), OperationType: $OperationType);
38-
$this->assertSame($expectedBinarName, $PostgresExecutor->getBinaryName());
41+
42+
$this->assertSame($expectedBinaryName, $PostgresExecutor->getBinaryName());
3943
}
4044
}

tests/TestCase/Executor/SqliteExecutorTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,22 @@ public function setUp(): void
4444
$this->SqliteExecutor = new SqliteExecutor(Connection: new FakeConnection(), OperationType: OperationType::Export);
4545
}
4646

47+
/**
48+
* @link \DatabaseBackup\Executor\SqliteExecutor::getBinaryName()
49+
*/
4750
#[Test]
4851
#[TestWith(['sqlite3', OperationType::Export])]
4952
#[TestWith(['sqlite3', OperationType::Import])]
50-
public function testGetBinaryName(string $expectedBinarName, OperationType $OperationType): void
53+
public function testGetBinaryName(string $expectedBinaryName, OperationType $OperationType): void
5154
{
5255
$SqliteExecutor = new SqliteExecutor(Connection: new FakeConnection(), OperationType: $OperationType);
53-
$this->assertSame($expectedBinarName, $SqliteExecutor->getBinaryName());
56+
57+
$this->assertSame($expectedBinaryName, $SqliteExecutor->getBinaryName());
5458
}
5559

60+
/**
61+
* @link \DatabaseBackup\Executor\SqliteExecutor::getAllTableSchemas()
62+
*/
5663
#[Test]
5764
public function testGetAllTableSchemas(): void
5865
{
@@ -63,6 +70,9 @@ public function testGetAllTableSchemas(): void
6370
$this->assertSame('comments', $result[1]->name());
6471
}
6572

73+
/**
74+
* @link \DatabaseBackup\Executor\SqliteExecutor::dropAllTables()
75+
*/
6676
#[Test]
6777
public function testDropAllTables(): void
6878
{
@@ -75,6 +85,9 @@ public function testDropAllTables(): void
7585
$SqliteExecutor->dropAllTables();
7686
}
7787

88+
/**
89+
* @link \DatabaseBackup\Executor\SqliteExecutor::beforeImport()
90+
*/
7891
#[Test]
7992
public function testBeforeImport(): void
8093
{

0 commit comments

Comments
 (0)