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

MySqlDumpSourceTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 33.96 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 18
loc 53
wmc 6
lcom 1
cbo 5
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}