Skip to content

Commit f7f0135

Browse files
Upgrade to Symfony 5 process component
1 parent acc0e86 commit f7f0135

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ language: php
55
php:
66
- 7.2
77
- 7.3
8+
- 7.4
89

910
services:
1011
- mysql

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": "makeabledk/laravel-backup-sql-check",
33
"license": "CC-BY-SA-4.0",
44
"require": {
5-
"php": ">=7.1.0"
5+
"php": ">=7.1.0",
6+
"symfony/process": "^5.0"
67
},
78
"require-dev": {
89
"spatie/laravel-backup": "^6.0",
9-
"friendsofphp/php-cs-fixer": "^2.3",
10-
"laravel/laravel": "5.7",
11-
"orchestra/testbench": "~3.5",
12-
"mockery/mockery": "^1.2"
10+
"laravel/laravel": "^7.0",
11+
"orchestra/testbench": "^5.0",
12+
"mockery/mockery": "^1.3"
1313
},
1414
"autoload": {
1515
"psr-4": {

phpunit.xml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,17 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false">
11-
<php>
12-
<ini name='display_errors' value='1' />
13-
</php>
1411
<testsuites>
1512
<testsuite name="Package Test Suite">
16-
<directory>./tests/</directory>
13+
<directory suffix="Test.php">./tests/</directory>
1714
</testsuite>
1815
</testsuites>
1916
<filter>
2017
<whitelist>
2118
<directory suffix=".php">src/</directory>
2219
</whitelist>
2320
</filter>
24-
<logging>
25-
<log type="tap" target="build/report.tap"/>
26-
<log type="junit" target="build/report.junit.xml"/>
27-
<log type="coverage-html" target="build/coverage"/>
28-
<log type="coverage-text" target="build/coverage.txt"/>
29-
<log type="coverage-clover" target="build/logs/clover.xml"/>
30-
</logging>
31-
</phpunit>
21+
<php>
22+
<ini name="display_errors" value="1"/>
23+
</php>
24+
</phpunit>

src/DbImporter/Databases/MySqlImporter.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Makeable\SqlCheck\DbImporter\Databases;
44

55
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Str;
67
use Makeable\SqlCheck\DbImporter\DbImporter;
78
use Makeable\SqlCheck\DbImporter\Exceptions\DatabaseImportFailed;
89
use Symfony\Component\Process\Exception\ProcessTimedOutException;
@@ -119,7 +120,7 @@ protected function checkIfImportWasSuccessful($databaseName, $credentials)
119120
{
120121
$rawTables = $this->runMysqlCommand(["USE `{$databaseName}`", 'SHOW TABLES'], $credentials)->getOutput();
121122

122-
if (! starts_with($rawTables, 'Tables_in') || ! count(explode(PHP_EOL, $rawTables)) > 1) {
123+
if (! Str::startsWith($rawTables, 'Tables_in') || ! count(explode(PHP_EOL, $rawTables)) > 1) {
123124
throw DatabaseImportFailed::databaseWasEmpty($rawTables);
124125
}
125126
}
@@ -137,11 +138,11 @@ protected function runMysqlCommand($mysqlCommands, $credentialsFile, $timeout =
137138

138139
$command = [
139140
"{$quote}{$this->dumpBinaryPath}mysql{$quote}",
140-
"--defaults-extra-file=\"{$credentialsFile}\"",
141+
"--defaults-extra-file='{$credentialsFile}'",
141142
];
142143

143144
if ($this->socket !== '') {
144-
$command[] = "--socket={$this->socket}";
145+
$command[] = "--socket='{$this->socket}'";
145146
}
146147

147148
foreach ($this->extraOptions as $extraOption) {
@@ -150,10 +151,11 @@ protected function runMysqlCommand($mysqlCommands, $credentialsFile, $timeout =
150151

151152
$command[] = "-e {$quote}".implode('; ', Arr::wrap($mysqlCommands))."{$quote}";
152153

153-
$process = new Process(implode(' ', $command));
154-
$process->setTimeout($timeout);
154+
$command = implode(' ', $command);
155155

156156
try {
157+
$process = Process::fromShellCommandline($command);
158+
$process->setTimeout($timeout);
157159
$process->run();
158160
} catch (ProcessTimedOutException $exception) {
159161
throw DatabaseImportFailed::timeoutExceeded($timeout);

src/DbImporter/DbImporterFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static function createFromConnection($dbConnectionName)
2626
->setHost(Arr::first(Arr::wrap($dbConfig['host'] ?? '')))
2727
->setDbName($dbConfig['database'])
2828
->setUserName($dbConfig['username'] ?? '')
29-
->setPassword($dbConfig['password'] ?? '');
29+
->setPassword($dbConfig['password'] ?? '')
30+
->setSocket($dbConfig['unix_socket'] ?? '');
3031

3132
if ($dbImporter instanceof MysqlImporter) {
3233
$dbImporter->setDbCharset(Arr::get($dbConfig, 'charset'));

tests/Feature/HealthySqlDumpTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Makeable\SqlCheck\Tests\Feature;
44

5+
use Illuminate\Support\Facades\Artisan;
56
use Illuminate\Support\Facades\DB;
67
use Illuminate\Support\Facades\Event;
78
use Makeable\SqlCheck\DiskSpace;
@@ -45,9 +46,11 @@ public function it_fails_when_backup_is_corrupt()
4546

4647
Event::fake();
4748

48-
$this->artisan('backup:monitor')->assertExitCode(0);
49+
Artisan::call('backup:monitor');
4950

5051
Event::assertDispatched(UnhealthyBackupWasFound::class);
52+
53+
$this->assertStringContainsString('unhealthy!', Artisan::output());
5154
}
5255

5356
/** @test */
@@ -57,10 +60,12 @@ public function it_fails_when_sql_process_exceed_the_timeout_limit()
5760

5861
Event::fake(UnhealthyBackupWasFound::class);
5962

60-
$this->artisan('backup:monitor')->assertExitCode(0);
63+
Artisan::call('backup:monitor');
6164

6265
Event::assertDispatched(UnhealthyBackupWasFound::class);
6366

67+
$this->assertStringContainsString('unhealthy!', Artisan::output());
68+
6469
// Manually remove database, because error exited code before deleting it
6570
DB::select('DROP DATABASE `healthy-sql-dump--backup--mysite-2019-09-16-08-00-07`');
6671
}
@@ -79,8 +84,10 @@ public function available()
7984

8085
Event::fake(UnhealthyBackupWasFound::class);
8186

82-
$this->artisan('backup:monitor')->assertExitCode(0);
87+
Artisan::call('backup:monitor');
8388

8489
Event::assertDispatched(UnhealthyBackupWasFound::class);
90+
91+
$this->assertStringContainsString('unhealthy!', Artisan::output());
8592
}
8693
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected function getEnvironmentSetUp($app)
3030
config()->set('database.connections.mysql.username', env('DB_USERNAME'));
3131
config()->set('database.connections.mysql.password', env('DB_PASSWORD'));
3232
config()->set('database.connections.mysql.database', env('DB_DATABASE'));
33+
config()->set('database.connections.mysql.unix_socket', env('DB_SOCKET'));
3334
config()->set('filesystems.disks.backup', [
3435
'driver' => 'local',
3536
'root' => __DIR__.'/stubs',

0 commit comments

Comments
 (0)