Skip to content

Add functionality for Laravel 5 and Unit Testing. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,36 @@
[![Quality Score](https://img.shields.io/scrutinizer/g/freekmurze/laravel-backup.svg?style=flat-square)](https://scrutinizer-ci.com/g/freekmurze/laravel-backup)
[![Total Downloads](https://img.shields.io/packagist/dt/freekmurze/laravel-backup.svg?style=flat-square)](https://packagist.org/packages/freekmurze/laravel-backup)

This package is in alpha state, do not use unless you know what you're doing


This package makes a dump-file from a mySQL database in Laravel 5.

## Install

Via Composer
Install via Composer using:

``` bash
$ composer require spatie/laravel-backup
```

To publish the configuration run:

``` bash
$ php artisan vendor:publish --provider="Spatie\DatabaseBackup\DatabaseBackupServiceProvider"
```

## Usage

To generate a dump-file run:

``` bash
$ php artisan db:backup
```

The dump-file will be placed in storage/db-dumps or the folder you specified in the config.

## Testing

Run the tests with:

``` bash
$ phpunit
```
Expand All @@ -40,6 +52,7 @@ If you discover any security related issues, please email [email protected] instea
## Credits

- [Freek Van der Herten](https://github.com/freekmurze)
- [Matthias De Winter](https://github.com/MatthiasDeWinter)
- [All Contributors](../../contributors)

## License
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
],
"require": {
"php" : ">=5.4.0",
"illuminate/support": "5.0.x",
"illuminate/console": "5.0.x",
"fabpot/php-cs-fixer": "~1.4"
"illuminate/support": "5.*",
"illuminate/console": "5.*",
"orchestra/testbench": "~3.0"
},
"require-dev": {
"laravel/framework": "5.*",
"phpunit/phpunit" : "4.*",
"mockery/mockery": "0.9.*",
"scrutinizer/ocular": "~1.1"
},
"autoload": {
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Databases/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public function getFileExtension()

protected function getDumpCommandPath()
{
return Config::get('backup::mysql.dump_command_path');
return Config::get('laravel-backup.mysql.dump_command_path');
}
}
28 changes: 28 additions & 0 deletions tests/ConsoleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Spatie\DatabaseBackup\Console;

class ConsoleTest extends PHPUnit_Framework_TestCase {

protected $console;

public function setUp()
{
$this->console = new Console();
}

public function testSuccess()
{
$this->assertTrue(
$this->console->run('true')
);
}

public function testFailure()
{
$this->assertTrue(
$this->console->run('false') !== false
);
}
}

23 changes: 23 additions & 0 deletions tests/DatabaseBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Spatie\DatabaseBackup\DatabaseBuilder;

class DatabaseBuilderTest extends PHPUnit_Framework_TestCase {

public function testMySQL()
{
$config = [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'port' => '3307',
];

$databaseBuilder = new DatabaseBuilder();
$database = $databaseBuilder->getDatabase($config);

$this->assertInstanceOf('Spatie\DatabaseBackup\Databases\MySQLDatabase', $database);
}
}
24 changes: 24 additions & 0 deletions tests/command/BackupCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Spatie\DatabaseBackup\Commands\BackupCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Orchestra\Testbench\TestCase;
use Mockery as m;

class BackupCommandTest extends TestCase {

public function setUp()
{
parent::setUp();
}

public function tearDown()
{
m::close();
}

public function testInit()
{
$this->assertTrue(true);
}
}
45 changes: 45 additions & 0 deletions tests/database/MySQLDatabaseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Spatie\DatabaseBackup\Databases\MySQLDatabase;
use Mockery as m;

class MySQLDatabaseTest extends PHPUnit_Framework_TestCase {

protected $console;
protected $database;

public function setUp()
{
parent::setUp();

$this->console = m::mock('Spatie\DatabaseBackup\Console');

$this->database = new MySQLDatabase(
$this->console, 'testDatabase', 'testUser', 'password', 'localhost', '3306'
);
}

public function tearDown()
{
m::close();
}

public function testFileExtension()
{
$this->assertEquals(
'sql', $this->database->getFileExtension()
);
}

public function testDump()
{
$this->console->shouldReceive('run')
->with("mysqldump --user='testUser' --password='password' --host='localhost' --port='3306' 'testDatabase' > 'testfile.sql'")
->once()
->andReturn(true);

$this->assertTrue(
$this->database->dump('testfile.sql')
);
}
}