Completed
Push — master ( c3143d...6d43d4 )
by Nikola
03:05
created

MySqlDumpSourceTest::successfulDumpAndCleanup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 17
rs 9.4286
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
/*
3
 * This file is part of the Backup package, an RunOpenCode project.
4
 *
5
 * (c) 2015 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * This project is fork of "kbond/php-backup", for full credits info, please
11
 * view CREDITS file that was distributed with this source code.
12
 */
13
namespace RunOpenCode\Backup\Tests\Source;
14
15
use Psr\Log\NullLogger;
16
use RunOpenCode\Backup\Event\BackupEvent;
17
use RunOpenCode\Backup\Event\BackupEvents;
18
use RunOpenCode\Backup\Source\MySqlDumpSource;
19
use Symfony\Component\EventDispatcher\EventDispatcher;
20
21
class MySqlDumpSourceTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @test
25
     */
26
    public function successfulDumpAndCleanup()
27
    {
28
        $settings = require_once file_exists($config = __DIR__ .'/../Fixtures/config/mysqldump.php') ? $config : __DIR__ .'/../Fixtures/config/mysqldump.dist.php';
29
        $source = new MySqlDumpSource($settings['database'], $settings['username'], $settings['password'], $settings['host'], $settings['port']);
30
31
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
32
33
        $files = $source->fetch();
34
35
        $this->assertSame(1, count($files), 'It should dump one mysql file.');
36
37
        $this->assertTrue(file_exists($files[0]->getPath()), 'That file should exist prior to termination of backup process.');
38
39
        $eventDispatcher->dispatch(BackupEvents::TERMINATE, new BackupEvent());
40
41
        $this->assertFalse(file_exists($files[0]->getPath()), 'That file should not exist after termination of backup process.');
42
    }
43
44
    /**
45
     * @test
46
     *
47
     * @expectedException \RunOpenCode\Backup\Exception\SourceException
48
     */
49
    public function connectionError()
50
    {
51
        $settings = require_once file_exists($config = __DIR__ .'/../Fixtures/config/mysqldump.php') ? $config : __DIR__ .'/../Fixtures/config/mysqldump.dist.php';
52
        $source = new MySqlDumpSource($settings['database'], $settings['username'], $settings['password'], 'www.non-existing-domain.com', $settings['port']);
53
54
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
55
56
        $source->fetch();
57
    }
58
59
    /**
60
     * @test
61
     *
62
     * @expectedException \RunOpenCode\Backup\Exception\SourceException
63
     */
64
    public function databaseError()
65
    {
66
        $settings = require_once file_exists($config = __DIR__ .'/../Fixtures/config/mysqldump.php') ? $config : __DIR__ .'/../Fixtures/config/mysqldump.dist.php';
67
        $source = new MySqlDumpSource('There is no way that you have database with this name.', $settings['username'], $settings['password'], $settings['host'], $settings['port']);
68
69
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
70
71
        $source->fetch();
72
    }
73
}