Skip to content

Commit fb527c3

Browse files
committed
Merge branch 'develop' into cakephp4
2 parents 9f6004a + e3967dc commit fb527c3

File tree

12 files changed

+169
-201
lines changed

12 files changed

+169
-201
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: "https://paypal.me/mirkopagliai"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
## 2.6 branch
77
### 2.6.6
8+
* tests have been optimized and speeded up;
89
* APIs are now generated by `phpDocumentor` and no longer by` apigen`.
910

1011
### 2.6.5

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ before_test:
2727

2828
install:
2929
- cd c:\
30-
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/php-7.2.24-nts-Win32-VC15-x86.zip
30+
- curl -fsS -o php.zip https://windows.php.net/downloads/releases/latest/php-7.2-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

phpcs.xml.dist

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
11
<?xml version="1.0"?>
2-
<ruleset>
2+
<ruleset name="cakephp-database-backup">
33
<arg value="p"/>
44
<file>.</file>
55

6-
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>
7-
8-
<rule ref="Generic.Commenting.Todo">
9-
<severity>0</severity>
10-
</rule>
11-
<rule ref="Generic.Files.LineLength.TooLong">
12-
<severity>0</severity>
13-
</rule>
14-
<rule ref="Generic.PHP.NoSilencedErrors.Discouraged">
15-
<severity>0</severity>
16-
</rule>
17-
<rule ref="Internal.NoCodeFound">
18-
<severity>0</severity>
19-
</rule>
20-
<rule ref="PSR12.ControlStructures.ControlStructureSpacing.CloseParenthesisLine">
21-
<severity>0</severity>
22-
</rule>
23-
<rule ref="PSR12.ControlStructures.ControlStructureSpacing.FirstExpressionLine">
24-
<severity>0</severity>
25-
</rule>
26-
<rule ref="PSR12.ControlStructures.ControlStructureSpacing.LineIndent">
27-
<severity>0</severity>
28-
</rule>
29-
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall">
30-
<severity>0</severity>
31-
</rule>
32-
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaMagicConstant">
33-
<severity>0</severity>
34-
</rule>
35-
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace.UseFromSameNamespace">
36-
<severity>0</severity>
37-
</rule>
38-
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceAfterDeclare">
39-
<severity>0</severity>
40-
</rule>
41-
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
42-
<exclude-pattern>/webroot</exclude-pattern>
43-
</rule>
44-
45-
<exclude-pattern>*.min.css</exclude-pattern>
46-
<exclude-pattern>*.min.js</exclude-pattern>
47-
<exclude-pattern>/config/Migrations</exclude-pattern>
48-
<exclude-pattern>/coverage</exclude-pattern>
49-
<exclude-pattern>/vendor</exclude-pattern>
6+
<rule ref="./vendor/mirko-pagliai/php-tools/sniffer-ruleset.xml"/>
507
</ruleset>

src/BackupTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
trait BackupTrait
2828
{
2929
/**
30-
* Valid extensions (as keys) and compressions (as values)
30+
* Valid extensions. Names as keys and compressions as values
3131
* @since 2.4.0
3232
* @var array
3333
*/
@@ -41,7 +41,7 @@ trait BackupTrait
4141
*/
4242
public function getAbsolutePath(string $path): string
4343
{
44-
return (new Filesystem())->isAbsolutePath($path) ? $path : $this->getTarget() . DS . $path;
44+
return (new Filesystem())->isAbsolutePath($path) ? $path : add_slash_term($this->getTarget()) . $path;
4545
}
4646

4747
/**
@@ -54,7 +54,7 @@ public function getAbsolutePath(string $path): string
5454
public function getBinary(string $name): string
5555
{
5656
$binary = Configure::read('DatabaseBackup.binaries.' . $name);
57-
is_true_or_fail($binary, sprintf('Binary for `%s` could not be found. You have to set its path manually', $name), RuntimeException::class);
57+
is_true_or_fail($binary, __d('database_backup', 'Binary for `{0}` could not be found. You have to set its path manually', $name), RuntimeException::class);
5858

5959
return $binary;
6060
}
@@ -120,7 +120,7 @@ public function getDriverName(?ConnectionInterface $connection = null): string
120120
{
121121
$connection = $connection ?: $this->getConnection();
122122

123-
return get_class_short_name(get_class($connection->getDriver()));
123+
return get_class_short_name($connection->getDriver());
124124
}
125125

126126
/**

src/TestSuite/DriverTestCase.php

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
namespace DatabaseBackup\TestSuite;
1616

1717
use Cake\Core\Configure;
18-
use Cake\Database\Connection;
1918
use Cake\Event\EventList;
2019
use DatabaseBackup\TestSuite\TestCase;
21-
use ErrorException;
2220

2321
/**
2422
* DriverTestCase class.
@@ -101,31 +99,6 @@ final protected function getAllRecords(): array
10199
return $records;
102100
}
103101

104-
/**
105-
* Internal method to mock a driver
106-
* @param array $methods The list of methods to mock
107-
* @return \MockBuilder
108-
* @since 2.6.1
109-
* @uses $Driver
110-
*/
111-
final protected function getMockForDriver(array $methods): object
112-
{
113-
return $this->getMockBuilder(get_class($this->Driver))
114-
->setMethods($methods)
115-
->setConstructorArgs([$this->getConnection()])
116-
->getMock();
117-
}
118-
119-
/**
120-
* Test for `__construct()` method
121-
* @return void
122-
* @test
123-
*/
124-
public function testConstruct()
125-
{
126-
$this->assertInstanceof(Connection::class, $this->getProperty($this->Driver, 'connection'));
127-
}
128-
129102
/**
130103
* Test for `export()` method
131104
* @return void
@@ -228,50 +201,6 @@ public function testExportExecutableWithCompression()
228201
}
229202
}
230203

231-
/**
232-
* Test for `export()` method on failure
233-
* @return void
234-
* @since 2.6.2
235-
* @test
236-
*/
237-
public function testExportOnFailure()
238-
{
239-
$this->expectException(ErrorException::class);
240-
$this->expectExceptionMessageRegExp('/^Failed with exit code `\d`$/');
241-
//Sets a no existing database
242-
$config = ['database' => 'noExisting'] + $this->Driver->getConfig();
243-
$this->setProperty($this->Driver, 'connection', new Connection($config));
244-
$this->Driver->export($this->getAbsolutePath('example.sql'));
245-
}
246-
247-
/**
248-
* Test for `export()` method. Export is stopped because the
249-
* `beforeExport()` method returns `false`
250-
* @return void
251-
* @test
252-
*/
253-
public function testExportStoppedByBeforeExport()
254-
{
255-
$backup = $this->getAbsolutePath('example.sql');
256-
$Driver = $this->getMockForDriver(['beforeExport']);
257-
$Driver->method('beforeExport')->will($this->returnValue(false));
258-
$this->assertFalse($Driver->export($backup));
259-
$this->assertFileNotExists($backup);
260-
}
261-
262-
/**
263-
* Test for `getConfig()` method
264-
* @return void
265-
* @test
266-
*/
267-
public function testGetConfig()
268-
{
269-
$this->assertNotEmpty($this->Driver->getConfig());
270-
$this->assertIsArray($this->Driver->getConfig());
271-
$this->assertNotEmpty($this->Driver->getConfig('name'));
272-
$this->assertNull($this->Driver->getConfig('noExistingKey'));
273-
}
274-
275204
/**
276205
* Test for `import()` method
277206
* @return void
@@ -319,39 +248,4 @@ public function testImportExecutableWithCompression()
319248
$this->assertEquals($expected, $result);
320249
}
321250
}
322-
323-
/**
324-
* Test for `import()` method on failure
325-
* @return void
326-
* @since 2.6.2
327-
* @test
328-
*/
329-
public function testImportOnFailure()
330-
{
331-
$backup = $this->getAbsolutePath('example.sql');
332-
333-
$this->expectException(ErrorException::class);
334-
$this->expectExceptionMessageRegExp('/^Failed with exit code `\d`$/');
335-
$this->Driver->export($backup);
336-
337-
//Sets a no existing database
338-
$config = ['database' => 'noExisting'] + $this->Driver->getConfig();
339-
$this->setProperty($this->Driver, 'connection', new Connection($config));
340-
$this->Driver->import($backup);
341-
}
342-
343-
/**
344-
* Test for `import()` method. Import is stopped because the
345-
* `beforeImport()` method returns `false`
346-
* @return void
347-
* @test
348-
*/
349-
public function testImportStoppedByBeforeExport()
350-
{
351-
$backup = $this->getAbsolutePath('example.sql');
352-
$Driver = $this->getMockForDriver(['beforeImport']);
353-
$Driver->method('beforeImport')->will($this->returnValue(false));
354-
$this->assertTrue($Driver->export($backup));
355-
$this->assertFalse($Driver->import($backup));
356-
}
357251
}

src/TestSuite/TestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,18 @@ protected function createSomeBackups(bool $sleep = false): array
8383

8484
return $files;
8585
}
86+
87+
/**
88+
* Internal method to mock a driver
89+
* @param string $className Driver class name
90+
* @param array $methods The list of methods to mock
91+
* @return \DatabaseBackup\Driver\Driver|\PHPUnit_Framework_MockObject_MockObject
92+
*/
93+
protected function getMockForDriver($className, array $methods)
94+
{
95+
return $this->getMockBuilder($className)
96+
->setMethods($methods)
97+
->setConstructorArgs([$this->getConnection('test')])
98+
->getMock();
99+
}
86100
}

tests/TestCase/BackupTraitTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,6 @@ public function testGetExtension()
165165
}
166166
}
167167

168-
/**
169-
* Test for `getTarget()` method
170-
* @test
171-
*/
172-
public function testGetTarget()
173-
{
174-
$this->assertEquals(Configure::read('DatabaseBackup.target'), $this->getTarget());
175-
}
176-
177168
/**
178169
* Test for `getValidCompressions()` method
179170
* @test

0 commit comments

Comments
 (0)