Skip to content

Commit b3b1bb0

Browse files
committed
Merge branch 'develop' into develop-next-release
2 parents 2ad6bdc + b959cab commit b3b1bb0

File tree

6 files changed

+108
-141
lines changed

6 files changed

+108
-141
lines changed

CHANGELOG.md

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

88
## 2.6 branch
99
### 2.6.6
10+
* tests have been optimized and speeded up;
1011
* APIs are now generated by `phpDocumentor` and no longer by` apigen`.
1112

1213
### 2.6.5

src/TestSuite/DriverTestCase.php

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

1616
use Cake\Core\Configure;
17-
use Cake\Database\Connection;
1817
use Cake\Event\EventList;
1918
use DatabaseBackup\TestSuite\TestCase;
20-
use ErrorException;
2119

2220
/**
2321
* DriverTestCase class.
@@ -100,31 +98,6 @@ final protected function getAllRecords()
10098
return $records;
10199
}
102100

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

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

src/TestSuite/TestCase.php

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

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

tests/TestCase/Driver/DriverTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
namespace DatabaseBackup\Test\TestCase\Driver;
1616

17+
use Cake\Database\Connection;
1718
use DatabaseBackup\Driver\Mysql;
1819
use DatabaseBackup\TestSuite\TestCase;
20+
use ErrorException;
1921
use RuntimeException;
2022

2123
/**
@@ -40,6 +42,47 @@ public function setUp()
4042
$this->Driver = new Mysql($this->getConnection('test'));
4143
}
4244

45+
/**
46+
* Test for `__construct()` method
47+
* @return void
48+
* @test
49+
*/
50+
public function testConstruct()
51+
{
52+
$this->assertInstanceof(Connection::class, $this->getProperty($this->Driver, 'connection'));
53+
}
54+
55+
/**
56+
* Test for `export()` method on failure
57+
* @return void
58+
* @since 2.6.2
59+
* @test
60+
*/
61+
public function testExportOnFailure()
62+
{
63+
$this->expectException(ErrorException::class);
64+
$this->expectExceptionMessageRegExp('/^Failed with exit code `\d`$/');
65+
//Sets a no existing database
66+
$config = ['database' => 'noExisting'] + $this->Driver->getConfig();
67+
$this->setProperty($this->Driver, 'connection', new Connection($config));
68+
$this->Driver->export($this->getAbsolutePath('example.sql'));
69+
}
70+
71+
/**
72+
* Test for `export()` method. Export is stopped because the
73+
* `beforeExport()` method returns `false`
74+
* @return void
75+
* @test
76+
*/
77+
public function testExportStoppedByBeforeExport()
78+
{
79+
$backup = $this->getAbsolutePath('example.sql');
80+
$Driver = $this->getMockForDriver(Mysql::class, ['beforeExport']);
81+
$Driver->method('beforeExport')->will($this->returnValue(false));
82+
$this->assertFalse($Driver->export($backup));
83+
$this->assertFileNotExists($backup);
84+
}
85+
4386
/**
4487
* Test for `getBinary()` method
4588
* @test
@@ -53,4 +96,52 @@ public function testGetBinary()
5396
$this->expectExceptionMessage('Binary for `noExisting` could not be found. You have to set its path manually');
5497
$this->invokeMethod($this->Driver, 'getBinary', ['noExisting']);
5598
}
99+
100+
/**
101+
* Test for `getConfig()` method
102+
* @return void
103+
* @test
104+
*/
105+
public function testGetConfig()
106+
{
107+
$this->assertNotEmpty($this->Driver->getConfig());
108+
$this->assertIsArray($this->Driver->getConfig());
109+
$this->assertNotEmpty($this->Driver->getConfig('name'));
110+
$this->assertNull($this->Driver->getConfig('noExistingKey'));
111+
}
112+
113+
/**
114+
* Test for `import()` method on failure
115+
* @return void
116+
* @since 2.6.2
117+
* @test
118+
*/
119+
public function testImportOnFailure()
120+
{
121+
$backup = $this->getAbsolutePath('example.sql');
122+
123+
$this->expectException(ErrorException::class);
124+
$this->expectExceptionMessageRegExp('/^Failed with exit code `\d`$/');
125+
$this->Driver->export($backup);
126+
127+
//Sets a no existing database
128+
$config = ['database' => 'noExisting'] + $this->Driver->getConfig();
129+
$this->setProperty($this->Driver, 'connection', new Connection($config));
130+
$this->Driver->import($backup);
131+
}
132+
133+
/**
134+
* Test for `import()` method. Import is stopped because the
135+
* `beforeImport()` method returns `false`
136+
* @return void
137+
* @test
138+
*/
139+
public function testImportStoppedByBeforeExport()
140+
{
141+
$backup = $this->getAbsolutePath('example.sql');
142+
$Driver = $this->getMockForDriver(Mysql::class, ['beforeImport']);
143+
$Driver->method('beforeImport')->will($this->returnValue(false));
144+
$this->assertTrue($Driver->export($backup));
145+
$this->assertFalse($Driver->import($backup));
146+
}
56147
}

tests/TestCase/Driver/MysqlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testImportExecutableWithCompression()
8888
*/
8989
public function testAfterExport()
9090
{
91-
$driver = $this->getMockForDriver(['deleteAuthFile']);
91+
$driver = $this->getMockForDriver(MySql::class, ['deleteAuthFile']);
9292
$driver->expects($this->once())->method('deleteAuthFile');
9393
$this->assertNull($driver->afterExport());
9494
}
@@ -99,7 +99,7 @@ public function testAfterExport()
9999
*/
100100
public function testAfterImport()
101101
{
102-
$driver = $this->getMockForDriver(['deleteAuthFile']);
102+
$driver = $this->getMockForDriver(MySql::class, ['deleteAuthFile']);
103103
$driver->expects($this->once())->method('deleteAuthFile');
104104
$this->assertNull($driver->afterImport());
105105
}

tests/TestCase/Driver/SqliteTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,13 @@ public function testImportExecutable()
6060
$this->assertEquals($expected, $this->invokeMethod($this->Driver, '_importExecutable'));
6161
}
6262

63-
/**
64-
* Test for `export()` method on failure
65-
* @test
66-
*/
67-
public function testExportOnFailure()
68-
{
69-
$this->Driver = $this->getMockForDriver(['_exportExecutableWithCompression']);
70-
$this->Driver->method('_exportExecutableWithCompression')
71-
->will($this->returnValue(sprintf(
72-
'%s %s .dump noExistingDir/dump.sql' . REDIRECT_TO_DEV_NULL,
73-
$this->Driver->getBinary('sqlite3'),
74-
$this->Driver->getConfig('database')
75-
)));
76-
parent::testExportOnFailure();
77-
}
78-
7963
/**
8064
* Test for `import()` method
8165
* @test
8266
*/
8367
public function testImport()
8468
{
8569
$this->loadFixtures();
86-
8770
parent::testImport();
8871
}
89-
90-
/**
91-
* Test for `import()` method on failure
92-
* @test
93-
*/
94-
public function testImportOnFailure()
95-
{
96-
$this->Driver = $this->getMockForDriver(['_importExecutableWithCompression', 'beforeImport']);
97-
$this->Driver->method('beforeImport')->will($this->returnValue(true));
98-
$this->Driver->method('_importExecutableWithCompression')->will($this->returnValue(sprintf(
99-
'%s %s .dump noExisting' . REDIRECT_TO_DEV_NULL,
100-
$this->Driver->getBinary('sqlite3'),
101-
$this->Driver->getConfig('database')
102-
)));
103-
parent::testImportOnFailure();
104-
}
10572
}

0 commit comments

Comments
 (0)