Skip to content

Commit a064886

Browse files
committed
updated for php-tools 1.4.1
1 parent 609bb3b commit a064886

File tree

10 files changed

+33
-23
lines changed

10 files changed

+33
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# 2.x branch
22
## 2.8 branch
3+
### 2.8.2
4+
* updated for `php-tools` 1.4.1.
5+
36
### 2.8.1
47
* fixed I18n translations;
58
* fixed [bug for `Command` class](https://github.com/mirko-pagliai/cakephp-database-backup/pull/54).

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
"homepage": "https://github.com/mirko-pagliai/cakephp-database-backup",
55
"type": "cakephp-plugin",
66
"license": "MIT",
7-
"authors": [{
7+
"authors": [
8+
{
89
"name": "Mirko Pagliai",
910
"email": "mirko.pagliai@gmail.com"
10-
}],
11+
}
12+
],
1113
"require": {
1214
"php": ">=7.2",
1315
"cakephp/cakephp": "^4.0",
14-
"mirko-pagliai/php-tools": "^1.3"
16+
"mirko-pagliai/php-tools": "^1.4.1"
1517
},
1618
"require-dev": {
1719
"cakephp/cakephp-codesniffer": "^4.0",

src/BackupTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Cake\Datasource\ConnectionManager;
2121
use InvalidArgumentException;
2222
use Symfony\Component\Filesystem\Filesystem;
23+
use Tools\Exceptionist;
2324

2425
/**
2526
* A trait that provides some methods used by all other classes
@@ -87,7 +88,7 @@ public function getDriver(?ConnectionInterface $connection = null): object
8788
$connection = $connection ?: $this->getConnection();
8889
$className = get_class_short_name($connection->getDriver());
8990
$driver = App::classname(sprintf('%s.%s', 'DatabaseBackup', $className), 'Driver');
90-
is_true_or_fail(
91+
Exceptionist::isTrue(
9192
$driver,
9293
__d('database_backup', 'The `{0}` driver does not exist', $className),
9394
InvalidArgumentException::class

src/Driver/Driver.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Cake\Event\EventListenerInterface;
2121
use DatabaseBackup\BackupTrait;
2222
use RuntimeException;
23+
use Tools\Exceptionist;
2324

2425
/**
2526
* Represents a driver containing all methods to export/import database backups
@@ -187,7 +188,7 @@ final public function export(string $filename): bool
187188
}
188189

189190
exec($this->_exportExecutableWithCompression($filename), $output, $returnVar);
190-
is_true_or_fail($returnVar === 0, __d('database_backup', 'Failed with exit code `{0}`', $returnVar));
191+
Exceptionist::isTrue($returnVar === 0, __d('database_backup', 'Failed with exit code `{0}`', $returnVar));
191192

192193
$this->dispatchEvent('Backup.afterExport');
193194

@@ -203,7 +204,7 @@ final public function export(string $filename): bool
203204
public function getBinary($name)
204205
{
205206
$binary = Configure::read('DatabaseBackup.binaries.' . $name);
206-
is_true_or_fail($binary, sprintf('Binary for `%s` could not be found. You have to set its path manually', $name), RuntimeException::class);
207+
Exceptionist::isTrue($binary, sprintf('Binary for `%s` could not be found. You have to set its path manually', $name), RuntimeException::class);
207208

208209
return $binary;
209210
}
@@ -244,7 +245,7 @@ final public function import(string $filename): bool
244245
}
245246

246247
exec($this->_importExecutableWithCompression($filename), $output, $returnVar);
247-
is_true_or_fail($returnVar === 0, __d('database_backup', 'Failed with exit code `{0}`', $returnVar));
248+
Exceptionist::isTrue($returnVar === 0, __d('database_backup', 'Failed with exit code `{0}`', $returnVar));
248249

249250
$this->dispatchEvent('Backup.afterImport');
250251

src/Utility/BackupExport.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use DatabaseBackup\BackupTrait;
2020
use InvalidArgumentException;
2121
use Symfony\Component\Filesystem\Filesystem;
22+
use Tools\Exceptionist;
2223

2324
/**
2425
* Utility to export databases
@@ -116,7 +117,7 @@ public function compression(?string $compression)
116117

117118
if ($compression) {
118119
$this->extension = array_search($compression, $this->getValidCompressions());
119-
is_true_or_fail(
120+
Exceptionist::isTrue(
120121
$this->extension,
121122
__d('database_backup', 'Invalid compression type'),
122123
InvalidArgumentException::class
@@ -153,11 +154,11 @@ public function filename(string $filename)
153154
], $filename);
154155

155156
$filename = $this->getAbsolutePath($filename);
156-
is_writable_or_fail(dirname($filename));
157-
is_true_or_fail(!file_exists($filename), __d('database_backup', 'File `{0}` already exists', $filename));
157+
Exceptionist::isWritable(dirname($filename));
158+
Exceptionist::isTrue(!file_exists($filename), __d('database_backup', 'File `{0}` already exists', $filename));
158159

159160
//Checks for extension
160-
is_true_or_fail(
161+
Exceptionist::isTrue(
161162
$this->getExtension($filename),
162163
__d('database_backup', 'Invalid file extension'),
163164
InvalidArgumentException::class

src/Utility/BackupImport.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use DatabaseBackup\BackupTrait;
1919
use InvalidArgumentException;
20+
use Tools\Exceptionist;
2021

2122
/**
2223
* Utility to import databases
@@ -60,10 +61,10 @@ public function __construct()
6061
public function filename(string $filename)
6162
{
6263
$filename = $this->getAbsolutePath($filename);
63-
is_readable_or_fail($filename);
64+
Exceptionist::isReadable($filename);
6465

6566
//Checks for extension
66-
is_true_or_fail(
67+
Exceptionist::isTrue(
6768
$this->getExtension($filename),
6869
__d('database_backup', 'Invalid file extension'),
6970
InvalidArgumentException::class
@@ -84,7 +85,7 @@ public function filename(string $filename)
8485
*/
8586
public function import(): string
8687
{
87-
is_true_or_fail(
88+
Exceptionist::isTrue(
8889
!empty($this->filename),
8990
__d('database_backup', 'You must first set the filename'),
9091
InvalidArgumentException::class

src/Utility/BackupManager.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use InvalidArgumentException;
2525
use Symfony\Component\Finder\Finder;
2626
use Symfony\Component\Finder\SplFileInfo;
27+
use Tools\Exceptionist;
2728

2829
/**
2930
* Utility to manage database backups
@@ -38,12 +39,13 @@ class BackupManager
3839
* The path can be relative to the backup directory
3940
* @return bool
4041
* @see https://github.com/mirko-pagliai/cakephp-database-backup/wiki/How-to-use-the-BackupManager-utility#delete
42+
* @throws \Tools\Exception\FileNotExistsException
4143
* @throws \Tools\Exception\NotWritableException
4244
*/
4345
public function delete(string $filename): bool
4446
{
4547
$filename = $this->getAbsolutePath($filename);
46-
is_writable_or_fail($filename);
48+
Exceptionist::isWritable($filename);
4749

4850
return unlink($filename);
4951
}
@@ -98,7 +100,7 @@ public function index(): Collection
98100
*/
99101
public function rotate(int $rotate): array
100102
{
101-
is_true_or_fail(
103+
Exceptionist::isTrue(
102104
is_positive($rotate),
103105
__d('database_backup', 'Invalid rotate value'),
104106
InvalidArgumentException::class
@@ -121,7 +123,7 @@ public function rotate(int $rotate): array
121123
protected function getEmailInstance(string $backup, string $recipient): Email
122124
{
123125
$file = $this->getAbsolutePath($backup);
124-
is_readable_or_fail($file);
126+
Exceptionist::isReadable($file);
125127
$basename = basename($file);
126128
$server = env('SERVER_NAME', 'localhost');
127129

tests/TestCase/Utility/BackupImportTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testFilename()
8686

8787
//With an invalid directory
8888
$this->expectException(NotReadableException::class);
89-
$this->expectExceptionMessage('File or directory `' . $this->BackupExport->getAbsolutePath('noExistingDir' . DS . 'backup.sql') . '` is not readable');
89+
$this->expectExceptionMessage('File or directory `' . $this->BackupExport->getAbsolutePath('noExistingDir' . DS . 'backup.sql') . '` does not exist');
9090
$this->BackupImport->filename('noExistingDir' . DS . 'backup.sql');
9191

9292
//With invalid extension

tests/TestCase/Utility/BackupManagerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use DatabaseBackup\Utility\BackupManager;
2424
use InvalidArgumentException;
2525
use Tools\Exception\NotReadableException;
26-
use Tools\Exception\NotWritableException;
2726

2827
/**
2928
* BackupManagerTest class
@@ -83,8 +82,8 @@ public function testDeleteAll()
8382
$this->assertEmpty($this->BackupManager->index()->toList());
8483

8584
//With a no existing file
86-
$this->expectException(NotWritableException::class);
87-
$this->expectExceptionMessage('File or directory `' . $this->getAbsolutePath('noExistingFile') . '` is not writable');
85+
$this->expectException(NotReadableException::class);
86+
$this->expectExceptionMessage('File or directory `' . $this->getAbsolutePath('noExistingFile') . '` does not exist');
8887
$this->BackupManager->delete('noExistingFile');
8988
}
9089

@@ -187,7 +186,7 @@ public function testSend()
187186
public function testSendInvalidFile()
188187
{
189188
$this->expectException(NotReadableException::class);
190-
$this->expectExceptionMessage('File or directory `' . Configure::read('DatabaseBackup.target') . DS . 'noExistingFile` is not readable');
189+
$this->expectExceptionMessage('File or directory `' . Configure::read('DatabaseBackup.target') . DS . 'noExistingFile` does not exist');
191190
$this->BackupManager->send('noExistingFile', 'recipient@example.com');
192191
}
193192
}

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.8.1
1+
2.8.2

0 commit comments

Comments
 (0)