Skip to content

Commit 18e657b

Browse files
Merge pull request #62 from mirko-pagliai/develop
Develop
2 parents b8e423e + 0dfd1bc commit 18e657b

23 files changed

+121
-125
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# 2.x branch
22
## 2.8 branch
3+
### 2.8.4
4+
* `BackupManager::delete()` returns the full path;
5+
* all methods provided by `BackupManager` can now be called statically, except
6+
for the `send()` method;
7+
* extensive improvement of function descriptions and tags;
8+
* ready for `phpunit` 9.
9+
310
### 2.8.3
411
* updated for `php-tools` 1.4.5;
512
* added `phpstan`, so fixed some code.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ You can install the plugin via composer:
2222
$ composer require --prefer-dist mirko-pagliai/cakephp-database-backup
2323
```
2424

25+
The current release requires at least CakePHP 4.0, PHP 7.2 and `phpunit` 8.0.
26+
2527
Instead, the [cakephp3](//github.com/mirko-pagliai/cakephp-database-backup/tree/cakephp3)
26-
branch is compatible with all previous versions of CakePHP from version 3.5.1.
28+
branch requires at least CakePHP 3.5.1, PHP 5.6 and `phpunit` 5.7.14.
2729
In this case, you can install the package as well:
2830

2931
```bash

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ before_test:
2727

2828
install:
2929
- cd c:\
30-
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/latest/php-7.2-nts-Win32-VC15-x86-latest.zip
30+
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/latest/php-7.3-nts-Win32-VC15-x86-latest.zip
3131
- 7z x php.zip -oc:\php > nul
3232
- cd c:\php
3333
- copy php.ini-production php.ini
3434
- echo date.timezone="UTC" >> php.ini
3535
- echo extension_dir=ext >> php.ini
36+
- echo extension=php_curl.dll >> php.ini
3637
- echo extension=php_openssl.dll >> php.ini
3738
- echo extension=php_intl.dll >> php.ini
3839
- echo extension=php_mbstring.dll >> php.ini

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"require": {
1414
"php": ">=7.2",
1515
"cakephp/cakephp": "^4.0",
16-
"mirko-pagliai/php-tools": "^1.4.5"
16+
"mirko-pagliai/php-tools": "^1.4.7"
1717
},
1818
"require-dev": {
1919
"cakephp/cakephp-codesniffer": "^4.0",
2020
"mirko-pagliai/me-tools": "^2.19",
21-
"phpunit/phpunit": "^8.0"
21+
"phpunit/phpunit": "^8.0|^9.0"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -39,16 +39,16 @@
3939
"@test",
4040
"@composer update",
4141
"@test",
42-
"@stan-setup",
4342
"@stan"
4443
],
4544
"cs-check": "phpcs --standard=phpcs.xml.dist",
4645
"cs-fix": "phpcbf --standard=phpcs.xml.dist",
4746
"test": "phpunit",
48-
"test-coverage": "phpunit --coverage-html coverage",
47+
"coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=coverage",
4948
"phpstan": "phpstan.phar analyse",
5049
"psalm": "psalm.phar",
5150
"stan": [
51+
"@stan-setup",
5252
"@phpstan",
5353
"@psalm"
5454
],

config/bootstrap.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
use Cake\Core\Configure;
1818
use Tools\Filesystem;
1919

20-
//Sets the redirect to `/dev/null`. This string can be concatenated to shell commands
20+
//Sets the redirect to `/dev/null`. This string will be concatenated to shell commands
2121
if (!defined('REDIRECT_TO_DEV_NULL')) {
2222
define('REDIRECT_TO_DEV_NULL', IS_WIN ? ' 2>nul' : ' 2>/dev/null');
2323
}
2424

25-
//Binaries
25+
//Auto-discovers binaries
2626
foreach (['bzip2', 'gzip', 'mysql', 'mysqldump', 'pg_dump', 'pg_restore', 'sqlite3'] as $binary) {
2727
if (!Configure::check('DatabaseBackup.binaries.' . $binary)) {
2828
Configure::write('DatabaseBackup.binaries.' . $binary, which($binary));
2929
}
3030
}
3131

32-
//Chmod for backups.
33-
//This works only on Unix
32+
//Default chmod for backups. This works only on Unix
3433
if (!Configure::check('DatabaseBackup.chmod')) {
3534
Configure::write('DatabaseBackup.chmod', 0664);
3635
}
@@ -47,7 +46,7 @@
4746

4847
//Default target directory
4948
if (!Configure::check('DatabaseBackup.target')) {
50-
Configure::write('DatabaseBackup.target', (new Filesystem())->addSlashTerm(ROOT) . 'backups');
49+
Configure::write('DatabaseBackup.target', Filesystem::instance()->concatenate(ROOT, 'backups'));
5150
}
5251

5352
//Checks for the target directory

phpstan.neon

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 6
2+
level: 7
33

44
paths:
55
- config
@@ -19,6 +19,7 @@ parameters:
1919
ignoreErrors:
2020
- '#(Ternary operator condition|Negated boolean expression) is always (true|false)\.$#'
2121
- "#^Constant REDIRECT_TO_DEV_NULL not found\\.$#"
22+
- '#^Parameter \#1 \$callback of function array_map expects \(callable\(\): mixed\)\|null#'
2223
- "#^Static call to instance method Tools\\\\Exceptionist#"
2324
- "#^Parameter \\#2 \\$eventManager of method Cake\\\\TestSuite\\\\TestCase\\:\\:assertEventFired\\(\\) expects Cake\\\\Event\\\\EventManager\\|null, Cake\\\\Event\\\\EventManagerInterface given\\.$#"
2425
- "#^Parameter \\#1 \\$connection of method Cake\\\\Database\\\\Schema\\\\TableSchema\\:\\:dropSql\\(\\) expects Cake\\\\Database\\\\Connection, Cake\\\\Datasource\\\\ConnectionInterface given\\.$#"
@@ -28,14 +29,9 @@ parameters:
2829
path: src/Driver/Sqlite.php
2930

3031
-
31-
message: "#^Unable to resolve the template type RealInstanceType#"
32-
path: src/TestSuite/TestCase.php
32+
message: '#^Call to an undefined method [\w\|\\]+MockObject::\w+\(\)\.$#'
33+
path: tests/TestCase
3334

3435
-
3536
message: '#has no return typehint specified\.$#'
3637
path: tests/TestCase
37-
38-
-
39-
message: "#^Binary operation \"\\+\" between#"
40-
count: 3
41-
path: tests/TestCase/Driver

psalm.xml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,47 @@
1515
</projectFiles>
1616

1717
<issueHandlers>
18-
<UndefinedConstant>
18+
<InvalidArgument>
1919
<errorLevel type="suppress">
20-
<file name="src/Driver/Driver.php" />
21-
<file name="src/TestSuite/DriverTestCase.php" />
20+
<file name="src/Driver/Sqlite.php" />
2221
</errorLevel>
23-
</UndefinedConstant>
22+
</InvalidArgument>
23+
24+
<InvalidDocblock>
25+
<errorLevel type="suppress">
26+
<file name="src/TestSuite/TestCase.php" />
27+
</errorLevel>
28+
</InvalidDocblock>
2429

2530
<RedundantCondition>
2631
<errorLevel type="suppress">
2732
<file name="src/Driver/Mysql.php" />
2833
</errorLevel>
2934
</RedundantCondition>
3035

31-
<UndefinedInterfaceMethod>
36+
<TooManyTemplateParams>
3237
<errorLevel type="suppress">
33-
<file name="src/Driver/Sqlite.php" />
38+
<file name="src/Utility/BackupManager.php" />
3439
</errorLevel>
35-
</UndefinedInterfaceMethod>
40+
</TooManyTemplateParams>
3641

3742
<UndefinedClass>
3843
<errorLevel type="suppress">
3944
<file name="src/BackupTrait.php" />
4045
</errorLevel>
4146
</UndefinedClass>
4247

43-
<InvalidArgument>
48+
<UndefinedConstant>
49+
<errorLevel type="suppress">
50+
<file name="src/Driver/Driver.php" />
51+
<file name="src/TestSuite/DriverTestCase.php" />
52+
</errorLevel>
53+
</UndefinedConstant>
54+
55+
<UndefinedInterfaceMethod>
4456
<errorLevel type="suppress">
4557
<file name="src/Driver/Sqlite.php" />
4658
</errorLevel>
47-
</InvalidArgument>
59+
</UndefinedInterfaceMethod>
4860
</issueHandlers>
4961
</psalm>

src/BackupTrait.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,13 @@ trait BackupTrait
3535
protected static $validExtensions = ['sql.bz2' => 'bzip2', 'sql.gz' => 'gzip', 'sql' => false];
3636

3737
/**
38-
* Returns an absolute path
38+
* Returns the absolute path for a backup file
3939
* @param string $path Relative or absolute path
4040
* @return string
4141
*/
42-
public function getAbsolutePath(string $path): string
42+
public static function getAbsolutePath(string $path): string
4343
{
44-
$Filesystem = new Filesystem();
45-
if (!$Filesystem->isAbsolutePath($path)) {
46-
return $Filesystem->addSlashTerm(Configure::read('DatabaseBackup.target')) . $path;
47-
}
48-
49-
return $path;
44+
return Filesystem::instance()->makePathAbsolute($path, Configure::read('DatabaseBackup.target'));
5045
}
5146

5247
/**
@@ -56,13 +51,11 @@ public function getAbsolutePath(string $path): string
5651
* @uses getExtension()
5752
* @uses getValidCompressions()
5853
*/
59-
public function getCompression(string $filename): ?string
54+
public static function getCompression(string $filename): ?string
6055
{
61-
//Gets the extension from the filename
62-
$extension = $this->getExtension($filename);
63-
$keyExists = array_key_exists($extension, $this->getValidCompressions());
56+
$extension = self::getExtension($filename);
6457

65-
return $keyExists ? $this->getValidCompressions()[$extension] : null;
58+
return self::getValidCompressions()[$extension] ?? null;
6659
}
6760

6861
/**
@@ -79,7 +72,7 @@ public function getConnection(?string $name = null): ConnectionInterface
7972
* Gets the driver instance containing all methods to export/import database
8073
* backups, according to the database engine
8174
* @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
82-
* @return object The driver instance
75+
* @return \DatabaseBackup\Driver\Driver A driver instance
8376
* @since 2.0.0
8477
* @throws \InvalidArgumentException
8578
* @uses getConnection()
@@ -101,20 +94,20 @@ public function getDriver(?ConnectionInterface $connection = null): object
10194
* if is an invalid extension
10295
* @uses $validExtensions
10396
*/
104-
public function getExtension(string $filename): ?string
97+
public static function getExtension(string $filename): ?string
10598
{
106-
$extension = (new Filesystem())->getExtension($filename);
99+
$extension = Filesystem::instance()->getExtension($filename);
107100

108101
return in_array($extension, array_keys(self::$validExtensions)) ? $extension : null;
109102
}
110103

111104
/**
112105
* Returns all valid compressions
113-
* @return array
106+
* @return array<string, string>
114107
* @since 2.4.0
115108
* @uses $validExtensions
116109
*/
117-
public function getValidCompressions(): array
110+
public static function getValidCompressions(): array
118111
{
119112
return array_filter(self::$validExtensions);
120113
}

src/Command/ExportCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
8686
//Regarding the `rotate` option, the `BackupShell::rotate()` method
8787
// will be called at the end, instead of `BackupExport::rotate()`
8888
if ($args->getOption('filename')) {
89-
$instance->filename($args->getOption('filename'));
89+
$instance->filename((string)$args->getOption('filename'));
9090
} elseif ($args->getOption('compression')) {
91-
$instance->compression($args->getOption('compression'));
91+
$instance->compression((string)$args->getOption('compression'));
9292
}
9393

9494
//Exports

src/Command/RotateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
6767
}
6868

6969
foreach ($files as $file) {
70-
$io->verbose(__d('database_backup', 'Backup `{0}` has been deleted', $file->filename));
70+
$io->verbose(__d('database_backup', 'Backup `{0}` has been deleted', $file->get('filename')));
7171
}
7272

7373
$io->success(__d('database_backup', 'Deleted backup files: {0}', count($files)));

0 commit comments

Comments
 (0)