Skip to content

Commit

Permalink
Merge pull request #5 from ARCANEDEV/update-1
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
arcanedev-maroc authored Sep 10, 2020
2 parents af2cb4c + d6447d4 commit b45794b
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 141 deletions.
4 changes: 3 additions & 1 deletion src/Database/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ public function echoToFile(string $dumpFile, Compressor $compressor = null): str
return "{$command} > {$dumpFile}";
}

return "(((({$command}; echo \$? >&3) | {$compressor->useCommand()} > {$dumpFile}) 3>&1) | (read x; exit \$x))";
return static::isWindowsOS()
? "{$command} | {$compressor->useCommand()} > {$dumpFile}"
: "(((({$command}; echo \$? >&3) | {$compressor->useCommand()} > {$dumpFile}) 3>&1) | (read x; exit \$x))";
}

/* -----------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions src/Database/Dumpers/MySqlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class MySqlDumper extends AbstractDumper
/** @var bool */
protected $skipLockTables = false;

/** @var bool */
protected $doNotUseColumnStatistics = false;

/** @var bool */
protected $useQuick = false;

Expand Down Expand Up @@ -146,6 +149,18 @@ public function skipLockTables()
return $this;
}

/**
* Skip the column statistics.
*
* @return $this
*/
public function doNotUseColumnStatistics()
{
$this->doNotUseColumnStatistics = true;

return $this;
}

/**
* Don't skip the lock tables.
*
Expand Down Expand Up @@ -259,6 +274,7 @@ public function getDumpCommand(string $dumpFile, string $temporaryCredentialsFil
->add($this->useExtendedInserts ? '--extended-insert' : '--skip-extended-insert')
->addIf($this->useSingleTransaction, '--single-transaction')
->addIf($this->skipLockTables, '--skip-lock-tables')
->addIf($this->doNotUseColumnStatistics, '--column-statistics=0')
->addIf($this->useQuick, '--quick')
->addUnless(is_null($this->getSocket()), "--socket={$this->getSocket()}")
->addMany(
Expand Down
2 changes: 1 addition & 1 deletion tests/BackupServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function setUp(): void
*/

/** @test */
public function it_can_be_instantiated()
public function it_can_be_instantiated(): void
{
$expectations = [
\Illuminate\Support\ServiceProvider::class,
Expand Down
14 changes: 7 additions & 7 deletions tests/Console/CleanupBackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp(): void
*/

/** @test */
public function it_can_remove_old_backups_until_using_less_than_maximum_storage()
public function it_can_remove_old_backups_until_using_less_than_maximum_storage(): void
{
$this->app['config']->set('backup.cleanup.strategy.delete-backups.oldest-when-size-reach', 2);

Expand All @@ -63,7 +63,7 @@ public function it_can_remove_old_backups_until_using_less_than_maximum_storage(
}

/** @test */
public function it_can_remove_old_backups_from_the_backup_directory()
public function it_can_remove_old_backups_from_the_backup_directory(): void
{
/** @var \Illuminate\Support\Collection $expectedRemainingBackups */
/** @var \Illuminate\Support\Collection $expectedDeletedBackups */
Expand Down Expand Up @@ -138,7 +138,7 @@ public function it_can_remove_old_backups_from_the_backup_directory()
}

/** @test */
public function it_will_leave_non_zip_files_alone()
public function it_will_leave_non_zip_files_alone(): void
{
$paths = Collection::make([
static::createFileOnDisk('primary-storage', 'ARCANEDEV/test1.txt', Carbon::now()->subDays(1)),
Expand All @@ -158,7 +158,7 @@ public function it_will_leave_non_zip_files_alone()
}

/** @test */
public function it_will_never_delete_the_newest_backup()
public function it_will_never_delete_the_newest_backup(): void
{
$backupPaths = Collection::make(range(5, 10))->map(function (int $numberOfYears) {
$date = Carbon::now()->subYears($numberOfYears);
Expand All @@ -181,7 +181,7 @@ public function it_will_never_delete_the_newest_backup()
}

/** @test */
public function it_should_trigger_the_cleanup_successful_event()
public function it_should_trigger_the_cleanup_successful_event(): void
{
$this->artisan('backup:clean')
->expectsOutput('Starting cleanup...')
Expand All @@ -193,7 +193,7 @@ public function it_should_trigger_the_cleanup_successful_event()
}

/** @test */
public function it_should_omit_the_cleanup_successful_event_when_the_notifications_are_disabled()
public function it_should_omit_the_cleanup_successful_event_when_the_notifications_are_disabled(): void
{
$this->artisan('backup:clean --disable-notifications')
->expectsOutput('Starting cleanup...')
Expand All @@ -205,7 +205,7 @@ public function it_should_omit_the_cleanup_successful_event_when_the_notificatio
}

/** @test */
public function it_should_display_correct_used_storage_amount_after_cleanup()
public function it_should_display_correct_used_storage_amount_after_cleanup(): void
{
$this->app['config']->set('backup.cleanup.strategy.delete-backups.oldest-when-size-reach', 4);

Expand Down
12 changes: 6 additions & 6 deletions tests/Console/MonitorBackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setUp(): void
*/

/** @test */
public function it_succeeds_when_destination_is_reachable()
public function it_succeeds_when_destination_is_reachable(): void
{
static::create1MbFileOnDisk('local', 'ARCANEDEV/test.zip', Carbon::now()->subSecond());

Expand All @@ -49,7 +49,7 @@ public function it_succeeds_when_destination_is_reachable()
}

/** @test */
public function it_fails_when_backup_destination_is_not_reachable()
public function it_fails_when_backup_destination_is_not_reachable(): void
{
$this->app['config']->set('backup.monitor.destinations.0.disks', ['not-real-disk']);

Expand All @@ -66,7 +66,7 @@ public function it_fails_when_backup_destination_is_not_reachable()
*/

/** @test */
public function it_succeeds_when_a_fresh_backup_present()
public function it_succeeds_when_a_fresh_backup_present(): void
{
$this->create1MbFileOnDisk('primary-storage', 'ARCANEDEV/test.zip', Carbon::now()->subSecond());

Expand All @@ -80,7 +80,7 @@ public function it_succeeds_when_a_fresh_backup_present()
}

/** @test */
public function it_fails_when_no_backups_are_present()
public function it_fails_when_no_backups_are_present(): void
{
$this->app['config']->set('backup.monitor.destinations.0.disks', ['primary-storage']);

Expand All @@ -92,7 +92,7 @@ public function it_fails_when_no_backups_are_present()
}

/** @test */
public function it_fails_when_max_days_has_been_exceeded()
public function it_fails_when_max_days_has_been_exceeded(): void
{
static::create1MbFileOnDisk('primary-storage', 'ARCANEDEV/test.zip', Carbon::now()->subSecond()->subDay());

Expand All @@ -106,7 +106,7 @@ public function it_fails_when_max_days_has_been_exceeded()
}

/** @test */
public function it_accepts_a_shorthand_value_in_config()
public function it_accepts_a_shorthand_value_in_config(): void
{
static::create1MbFileOnDisk('primary-storage', 'ARCANEDEV/test.zip', Carbon::now()->subSecond()->subDay());

Expand Down
6 changes: 3 additions & 3 deletions tests/Console/RunBackupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ protected function assertTemporaryDirectoryNotExists(): void
static::assertFalse(file_exists(storage_path('app/_backup-temp')));
}

protected static function assertBackupsExistsInStorages(array $disks = ['primary-storage', 'secondary-storage'])
protected static function assertBackupsExistsInStorages(array $disks = ['primary-storage', 'secondary-storage']): void
{
foreach ($disks as $disk) {
Storage::disk($disk)->assertExists('ARCANEDEV/20190101-123030.zip');
}
}

protected static function assertBackupFilesExistsInZipFile(array $files, array $disks = ['primary-storage', 'secondary-storage'])
protected static function assertBackupFilesExistsInZipFile(array $files, array $disks = ['primary-storage', 'secondary-storage']): void
{
foreach ($disks as $disk) {
$path = Storage::disk($disk)->path('ARCANEDEV/20190101-123030.zip');
Expand All @@ -147,7 +147,7 @@ protected static function assertBackupFilesExistsInZipFile(array $files, array $
}
}

protected static function assertBackupsMissingInStorages(array $disks = ['primary-storage', 'secondary-storage'])
protected static function assertBackupsMissingInStorages(array $disks = ['primary-storage', 'secondary-storage']): void
{
foreach ($disks as $disk) {
Storage::disk($disk)->assertMissing('ARCANEDEV/20190101-123030.zip');
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DbDumperManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ protected function setUp(): void
*/

/** @test */
public function it_can_be_instantiated()
public function it_can_be_instantiated(): void
{
static::assertInstanceOf(DbDumperManager::class, $this->manager);
}

/** @test */
public function it_must_throw_exception_on_unsupported_connection()
public function it_must_throw_exception_on_unsupported_connection(): void
{
$this->expectException(\Arcanedev\LaravelBackup\Exceptions\CannotCreateDbDumper::class);
$this->expectExceptionMessage(
Expand All @@ -66,7 +66,7 @@ public function it_must_throw_exception_on_unsupported_connection()
* @param string $driver
* @param string $class
*/
public function it_can_get_db_dumper_based_on_given_driver(string $driver, string $class)
public function it_can_get_db_dumper_based_on_given_driver(string $driver, string $class): void
{
$dumper = $this->manager->dumper($driver);

Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Dumpers/DumpTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class DumpTestCase extends TestCase
* @param string $expected
* @param string $actual
*/
public function assertSameCommand(string $expected, string $actual)
public function assertSameCommand(string $expected, string $actual): void
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$expected = str_replace('\'', '"', $expected);
Expand Down
20 changes: 10 additions & 10 deletions tests/Database/Dumpers/MongoDbDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ protected function setUp(): void
*/

/** @test */
public function it_provides_a_factory_method()
public function it_provides_a_factory_method(): void
{
static::assertInstanceOf(MongoDbDumper::class, $this->dumper);
}

/** @test */
public function it_will_throw_an_exception_when_no_credentials_are_set()
public function it_will_throw_an_exception_when_no_credentials_are_set(): void
{
$this->expectException(CannotStartDatabaseDump::class);

$this->dumper->dump('test.gz');
}

/** @test */
public function it_can_generate_a_dump_command()
public function it_can_generate_a_dump_command(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -67,7 +67,7 @@ public function it_can_generate_a_dump_command()
}

/** @test */
public function it_can_generate_a_dump_command_with_gzip_compressor_enabled()
public function it_can_generate_a_dump_command_with_gzip_compressor_enabled(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -80,7 +80,7 @@ public function it_can_generate_a_dump_command_with_gzip_compressor_enabled()
}

/** @test */
public function it_can_generate_a_dump_command_with_absolute_path_having_space_and_brackets()
public function it_can_generate_a_dump_command_with_absolute_path_having_space_and_brackets(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -92,7 +92,7 @@ public function it_can_generate_a_dump_command_with_absolute_path_having_space_a
}

/** @test */
public function it_can_generate_a_dump_command_with_username_and_password()
public function it_can_generate_a_dump_command_with_username_and_password(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -106,7 +106,7 @@ public function it_can_generate_a_dump_command_with_username_and_password()
}

/** @test */
public function it_can_generate_a_command_with_custom_host_and_port()
public function it_can_generate_a_command_with_custom_host_and_port(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -120,7 +120,7 @@ public function it_can_generate_a_command_with_custom_host_and_port()
}

/** @test */
public function it_can_generate_a_backup_command_for_a_single_collection()
public function it_can_generate_a_backup_command_for_a_single_collection(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -133,7 +133,7 @@ public function it_can_generate_a_backup_command_for_a_single_collection()
}

/** @test */
public function it_can_generate_a_dump_command_with_custom_binary_path()
public function it_can_generate_a_dump_command_with_custom_binary_path(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand All @@ -146,7 +146,7 @@ public function it_can_generate_a_dump_command_with_custom_binary_path()
}

/** @test */
public function it_can_generate_a_dump_command_with_authentication_database()
public function it_can_generate_a_dump_command_with_authentication_database(): void
{
$actual = $this->dumper
->setDbName('dbname')
Expand Down
Loading

0 comments on commit b45794b

Please sign in to comment.