Skip to content

Commit 17f6523

Browse files
Merge feat/php8 (#16)
* Add GH Action * Apply fixes from StyleCI (#15) * Fix test
1 parent f8a1349 commit 17f6523

File tree

12 files changed

+103
-71
lines changed

12 files changed

+103
-71
lines changed

.github/workflows/test.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
services:
13+
mysql:
14+
image: mysql:5.7
15+
env:
16+
MYSQL_DATABASE: laravel_backup_sql_check
17+
MYSQL_ROOT_PASSWORD: root
18+
ports:
19+
- 3306
20+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
php: [8.0,8.1]
26+
laravel: [8.*,9.*]
27+
dependency-version: [prefer-lowest,prefer-stable]
28+
29+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v1
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
coverage: none
40+
41+
- name: Install dependencies
42+
run: |
43+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
44+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
45+
46+
- name: Execute tests
47+
run: vendor/bin/phpunit
48+
env:
49+
DB_CONNECTION: mysql
50+
DB_HOST: 127.0.0.1
51+
DB_PORT: ${{ job.services.mysql.ports[3306] }}
52+
DB_DATABASE: laravel_backup_sql_check
53+
DB_USERNAME: root
54+
DB_PASSWORD: root

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
composer.phar
33
composer.lock
44
vendor
5-
.env
5+
.env
6+
.phpunit.result.cache

.phpunit.result.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"name": "makeabledk/laravel-backup-sql-check",
33
"license": "CC-BY-SA-4.0",
44
"require": {
5-
"php": ">=7.3.0",
6-
"symfony/process": "^5.0"
5+
"php": "^8.0",
6+
"symfony/process": "^5.0|^6.0"
77
},
88
"require-dev": {
9-
"spatie/laravel-backup": "^6.0",
10-
"laravel/laravel": "^8.0",
9+
"spatie/laravel-backup": "^7.0|^8.0",
10+
"laravel/laravel": "^8.6.10|^9.0",
11+
"phpunit/phpunit": "^9.0",
1112
"orchestra/testbench": "^6.0",
12-
"mockery/mockery": "^1.3"
13+
"mockery/mockery": "^1.5"
1314
},
1415
"autoload": {
1516
"psr-4": {

src/DbImporter/Databases/MySqlImporter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MySqlImporter extends DbImporter
2626
* @param $dumpFile
2727
* @param $timeout
2828
* @return mixed|void
29+
*
2930
* @throws DatabaseImportFailed
3031
*/
3132
public function createDatabaseFromFile($databaseName, $dumpFile, $timeout)
@@ -40,6 +41,7 @@ public function createDatabaseFromFile($databaseName, $dumpFile, $timeout)
4041
/**
4142
* @param $databaseName
4243
* @return mixed|void
44+
*
4345
* @throws DatabaseImportFailed
4446
*/
4547
public function dropDatabase($databaseName)
@@ -74,6 +76,7 @@ public function setDbCollation($dbCollation)
7476
/**
7577
* @param $file
7678
* @return mixed
79+
*
7780
* @throws DatabaseImportFailed
7881
*/
7982
protected function configureCredentials($file)
@@ -96,6 +99,7 @@ protected function configureCredentials($file)
9699
* @param $file
97100
* @param $credentials
98101
* @param $timeout
102+
*
99103
* @throws DatabaseImportFailed
100104
*/
101105
protected function createDatabase($databaseName, $file, $credentials, $timeout)
@@ -114,6 +118,7 @@ protected function createDatabase($databaseName, $file, $credentials, $timeout)
114118
/**
115119
* @param $databaseName
116120
* @param $credentials
121+
*
117122
* @throws DatabaseImportFailed
118123
*/
119124
protected function checkIfImportWasSuccessful($databaseName, $credentials)
@@ -130,6 +135,7 @@ protected function checkIfImportWasSuccessful($databaseName, $credentials)
130135
* @param $credentialsFile
131136
* @param $timeout
132137
* @return Process
138+
*
133139
* @throws DatabaseImportFailed
134140
*/
135141
protected function runMysqlCommand($mysqlCommands, $credentialsFile, $timeout = 60)

src/DbImporter/DbImporter.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public static function create()
5757
}
5858

5959
/**
60-
* @param string $extraOption
61-
*
60+
* @param string $extraOption
6261
* @return $this
6362
*/
6463
public function addExtraOption($extraOption)
@@ -76,8 +75,7 @@ public function getDbName()
7675
}
7776

7877
/**
79-
* @param string $dbName
80-
*
78+
* @param string $dbName
8179
* @return $this
8280
*/
8381
public function setDbName($dbName)
@@ -88,8 +86,7 @@ public function setDbName($dbName)
8886
}
8987

9088
/**
91-
* @param string $userName
92-
*
89+
* @param string $userName
9390
* @return $this
9491
*/
9592
public function setUserName($userName)
@@ -100,8 +97,7 @@ public function setUserName($userName)
10097
}
10198

10299
/**
103-
* @param string $password
104-
*
100+
* @param string $password
105101
* @return $this
106102
*/
107103
public function setPassword($password)
@@ -112,8 +108,7 @@ public function setPassword($password)
112108
}
113109

114110
/**
115-
* @param string $host
116-
*
111+
* @param string $host
117112
* @return $this
118113
*/
119114
public function setHost($host)
@@ -129,8 +124,7 @@ public function getHost()
129124
}
130125

131126
/**
132-
* @param int $port
133-
*
127+
* @param int $port
134128
* @return $this
135129
*/
136130
public function setPort($port)
@@ -141,8 +135,7 @@ public function setPort($port)
141135
}
142136

143137
/**
144-
* @param string $socket
145-
*
138+
* @param string $socket
146139
* @return $this
147140
*/
148141
public function setSocket($socket)
@@ -153,8 +146,7 @@ public function setSocket($socket)
153146
}
154147

155148
/**
156-
* @param int $timeout
157-
*
149+
* @param int $timeout
158150
* @return $this
159151
*/
160152
public function setTimeout($timeout)

src/DbImporter/DbImporterFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class DbImporterFactory
1111
/**
1212
* @param $dbConnectionName
1313
* @return DbImporter
14+
*
1415
* @throws Exception
1516
*/
1617
public static function createFromConnection($dbConnectionName)
@@ -44,6 +45,7 @@ public static function createFromConnection($dbConnectionName)
4445
/**
4546
* @param $dbDriver
4647
* @return MysqlImporter
48+
*
4749
* @throws Exception
4850
*/
4951
protected static function forDriver($dbDriver)

src/DbImporter/Exceptions/DatabaseImportFailed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function missingCredentials($name)
1717
}
1818

1919
/**
20-
* @param \Symfony\Component\Process\Process $process
20+
* @param \Symfony\Component\Process\Process $process
2121
* @return DatabaseImportFailed
2222
*/
2323
public static function processDidNotEndSuccessfully(Process $process)

src/HealthySqlDump.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ class HealthySqlDump extends HealthCheck
2222

2323
/**
2424
* HealthySqlDump constructor.
25-
* @param float $timeout
25+
*
26+
* @param float $timeout
2627
*/
2728
public function __construct(float $timeout = 60)
2829
{
2930
$this->timeout = $timeout;
3031
}
3132

3233
/**
33-
* @param BackupDestination $backupDestination
34+
* @param BackupDestination $backupDestination
35+
*
3436
* @throws \Spatie\Backup\Exceptions\InvalidHealthCheck
3537
* @throws \Throwable
3638
*/
@@ -60,8 +62,9 @@ public function checkHealth(BackupDestination $backupDestination)
6062
}
6163

6264
/**
63-
* @param BackupDestination $backupDestination
64-
* @param Backup $backup
65+
* @param BackupDestination $backupDestination
66+
* @param Backup $backup
67+
*
6568
* @throws \Spatie\Backup\Exceptions\InvalidHealthCheck
6669
*/
6770
public function performCheck(BackupDestination $backupDestination, Backup $backup)
@@ -81,8 +84,8 @@ public function performCheck(BackupDestination $backupDestination, Backup $backu
8184
}
8285

8386
/**
84-
* @param BackupDestination $destination
85-
* @param Backup $backup
87+
* @param BackupDestination $destination
88+
* @param Backup $backup
8689
* @return TemporaryDirectory
8790
*/
8891
protected function setupTempDirectory(BackupDestination $destination, Backup $backup)
@@ -95,9 +98,10 @@ protected function setupTempDirectory(BackupDestination $destination, Backup $ba
9598
}
9699

97100
/**
98-
* @param Backup $backup
99-
* @param TemporaryDirectory $temporaryDirectory
101+
* @param Backup $backup
102+
* @param TemporaryDirectory $temporaryDirectory
100103
* @return string
104+
*
101105
* @throws \Spatie\Backup\Exceptions\InvalidHealthCheck
102106
*/
103107
protected function downloadAndExtract(Backup $backup, TemporaryDirectory $temporaryDirectory)
@@ -132,6 +136,7 @@ protected function extract($source)
132136

133137
/**
134138
* @param $backup
139+
*
135140
* @throws \Spatie\Backup\Exceptions\InvalidHealthCheck
136141
*/
137142
protected function failsOnEmpty($backup)
@@ -143,6 +148,7 @@ protected function failsOnEmpty($backup)
143148

144149
/**
145150
* @param $backup
151+
*
146152
* @throws \Spatie\Backup\Exceptions\InvalidHealthCheck
147153
*/
148154
protected function failsOnNoSql($backup)
@@ -153,12 +159,13 @@ protected function failsOnNoSql($backup)
153159
}
154160

155161
/**
156-
* @param Backup $backup
162+
* @param Backup $backup
163+
*
157164
* @throws DatabaseImportFailed
158165
*/
159166
protected function failsOnInsufficientDiskSpace(Backup $backup)
160167
{
161-
$estimatedSqlSize = $backup->size() * 11; // Based on avg ZIP compression rates in production samples
168+
$estimatedSqlSize = $backup->sizeInBytes() * 11; // Based on avg ZIP compression rates in production samples
162169
$requiredSpace = $estimatedSqlSize * 2;
163170

164171
$diskSpace = app(DiskSpace::class);
@@ -169,7 +176,7 @@ protected function failsOnInsufficientDiskSpace(Backup $backup)
169176
}
170177

171178
/**
172-
* @param \SplFileInfo $fileInfo
179+
* @param \SplFileInfo $fileInfo
173180
* @return string
174181
*/
175182
protected function getConnectionFromFile(\SplFileInfo $fileInfo)

0 commit comments

Comments
 (0)