Skip to content

Commit 14ff782

Browse files
isaackaarafreekmurzeclaude
authored
Fix callMethodOnDumper treating false config values as no-argument calls (#1961)
* Fix callMethodOnDumper treating false as no-argument call When a dump config option like skip_ssl is set to false, callMethodOnDumper was calling the method with no arguments because of the falsy check: if (! $methodValue) { $dbDumper->$methodName(); } setSkipSsl() has a default parameter of true, so calling it with no arguments sets skipSsl to true even when the config says false. Change the check to $methodValue === null so only genuinely absent values (flag-style options like use_single_transaction) invoke the no-argument form. Falsy values like false and 0 are now passed through correctly. Fixes: #1946 * Reset custom dumpers in beforeEach to fix test isolation The 'custom dumpers' test registers a MongoDb factory for 'mysql' via the static $custom property, which persisted into subsequent tests causing the skip_ssl test to get a MongoDb instance instead of MySql. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Freek Van der Herten <freek@spatie.be> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 28f078d commit 14ff782

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Tasks/Backup/DbDumperFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected static function processExtraDumpParameters(array $dumpConfiguration, D
121121

122122
protected static function callMethodOnDumper(DbDumper $dbDumper, string $methodName, mixed $methodValue): DbDumper
123123
{
124-
if (! $methodValue) {
124+
if ($methodValue === null) {
125125
$dbDumper->$methodName();
126126

127127
return $dbDumper;

tests/DbDumperFactoryTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
use Spatie\DbDumper\Databases\Sqlite;
1010

1111
beforeEach(function () {
12+
$reflection = new \ReflectionClass(DbDumperFactory::class);
13+
$property = $reflection->getProperty('custom');
14+
$property->setValue(null, []);
15+
1216
config()->set('database.default', 'mysql');
1317

1418
config()->set('database.connections.mariadb', [
@@ -220,3 +224,26 @@ function getDumpCommand(): string
220224

221225
return DbDumperFactory::createFromConnection('mysql')->getDumpCommand($dumpFile, $credentialsFile);
222226
}
227+
228+
it('respects skip_ssl false when set in dump config', function () {
229+
$dbConfig = [
230+
'driver' => 'mysql',
231+
'host' => 'localhost',
232+
'database' => 'myDb',
233+
'username' => 'root',
234+
'password' => 'myPassword',
235+
'dump' => [
236+
'skip_ssl' => false,
237+
],
238+
];
239+
240+
config()->set('database.connections.mysql', $dbConfig);
241+
242+
$dumper = DbDumperFactory::createFromConnection('mysql');
243+
244+
$reflection = new \ReflectionClass($dumper);
245+
$property = $reflection->getProperty('skipSsl');
246+
$property->setAccessible(true);
247+
248+
expect($property->getValue($dumper))->toBeFalse();
249+
});

0 commit comments

Comments
 (0)