Skip to content

Commit

Permalink
Merge pull request #12 from mirko-pagliai/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mirko-pagliai authored Sep 2, 2017
2 parents d7e03ab + 1f5d023 commit 1bc811a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 2.x branch
## 2.1 branch
### 2.1.4
* when a backup is sent by mail, the mimetype is forced;
* fixed some tests.

### 2.1.3
* added `createBackup()` and `createSomeBackups()` to the `TestCase` class;
* `BackupManager::_send()` has become `getEmailInstance()`.
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
*DatabaseBackup* is a CakePHP plugin to export, import and manage database backups.
Currently, the plugin supports *MySql*, *Postgres* and *Sqlite* databases.

**NOTE**: this plugin requires at least version 3.4 of CakePHP.

## Installation
You can install the plugin via composer:

$ composer require --prefer-dist mirko-pagliai/cakephp-database-backup

**NOTE**: the package may require one of the latest versions version of CakePHP.
Instead, the [cakephp3.2](//github.com/mirko-pagliai/cakephp-database-backup/tree/cakephp3.2)
branch is compatible with CakePHP versions from 3.2 onwards.
In this case, you can install the package as well:

$ composer require --prefer-dist mirko-pagliai/cakephp-database-backup:dev-cakephp3.2

Then you have to edit `APP/config/bootstrap.php` to load the plugin:
After installation, you have to edit `APP/config/bootstrap.php` to load the plugin:

Plugin::load('DatabaseBackup', ['bootstrap' => true]);

Expand Down
1 change: 1 addition & 0 deletions src/TestSuite/DriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function setUp()

$connection = $this->getConnection();

TableRegistry::clear();
$this->Articles = TableRegistry::get('Articles', compact('connection'));
$this->Comments = TableRegistry::get('Comments', compact('connection'));

Expand Down
5 changes: 4 additions & 1 deletion src/Utility/BackupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ protected function getEmailInstance($backup, $recipient)
->setFrom($sender)
->setTo($recipient)
->setSubject(__d('database_backup', 'Database backup {0} from {1}', basename($backup), env('SERVER_NAME', 'localhost')))
->setAttachments($backup);
->setAttachments([basename($backup) => [
'file' => $backup,
'mimetype' => mime_content_type($backup),
]]);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions tests/TestCase/Driver/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace DatabaseBackup\Test\TestCase\Driver;

use Cake\Datasource\ConnectionManager;
use DatabaseBackup\BackupTrait;
use DatabaseBackup\Driver\Mysql;
use DatabaseBackup\TestSuite\DriverTestCase;
Expand Down Expand Up @@ -122,7 +123,10 @@ public function testBeforeExport()

$this->Driver->beforeExport();

$expected = '[mysqldump]' . PHP_EOL . 'user=travis' . PHP_EOL . 'password=""' . PHP_EOL . 'host=localhost';
$expected = '[mysqldump]' . PHP_EOL .
'user=' . ConnectionManager::config('test')['username'] . PHP_EOL .
'password=""' . PHP_EOL .
'host=localhost';
$auth = $this->getProperty($this->Driver, 'auth');
$this->assertFileExists($auth);
$this->assertEquals($expected, file_get_contents($auth));
Expand All @@ -140,7 +144,10 @@ public function testBeforeImport()

$this->Driver->beforeImport();

$expected = '[client]' . PHP_EOL . 'user=travis' . PHP_EOL . 'password=""' . PHP_EOL . 'host=localhost';
$expected = '[client]' . PHP_EOL .
'user=' . ConnectionManager::config('test')['username'] . PHP_EOL .
'password=""' . PHP_EOL .
'host=localhost';
$auth = $this->getProperty($this->Driver, 'auth');
$this->assertFileExists($auth);
$this->assertEquals($expected, file_get_contents($auth));
Expand Down
9 changes: 3 additions & 6 deletions tests/TestCase/Shell/BackupShellTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ public function testWelcome()
{
$this->invokeMethod($this->BackupShell, '_welcome');

$messages = $this->out->messages();

$this->assertRegExp('/^Connection: test/', $messages[6]);
$this->assertEquals('Driver: Mysql', $messages[7]);
$this->assertRegExp('/^\-+$/', $messages[8]);
$this->assertContains('Connection: test', $this->out->messages());
$this->assertContains('Driver: Mysql', $this->out->messages());
}

/**
Expand Down Expand Up @@ -371,7 +368,7 @@ public function testGetOptionParser()

$this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $parser);
$this->assertEquals([
'deleteAll',
'delete_all',
'export',
'import',
'index',
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
],
]);

ConnectionManager::setConfig('test', ['url' => 'mysql://travis@localhost/test']);
ConnectionManager::setConfig('test_sqlite', ['url' => 'sqlite:\\' . TMP . 'example.sq3']);
ConnectionManager::setConfig('test', ['url' => 'mysql://root@localhost/test']);
ConnectionManager::setConfig('test_sqlite', ['url' => 'sqlite:///' . TMP . 'example.sq3']);
ConnectionManager::setConfig('test_postgres', ['url' => 'postgres://postgres@localhost/travis_ci_test']);

Configure::write('DatabaseBackup.connection', 'test');
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4

0 comments on commit 1bc811a

Please sign in to comment.