Completed
Push — master ( d7c148...f76de2 )
by Nikola
02:27
created

MySqlDumpSourceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 7
dl 20
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A successfulDumpAndCleanup() 0 18 1
A connectionError() 10 10 1
A databaseError() 10 10 1

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\Source\MySqlDump;
18
use RunOpenCode\Backup\Tests\Source\Mockup\NullProfile;
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 __DIR__ .'/../Fixtures/config/mysqldump.php';
29
        $source = new MySqlDump($settings['database'], $settings['username'], $settings['password'], $settings['host'], $settings['port']);
30
31
        $source->setLogger(new NullLogger());
32
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
33
34
        $files = $source->fetch();
35
36
        $this->assertSame(1, count($files), 'It should dump one mysql file.');
37
38
        $this->assertTrue(file_exists($files[0]->getPath()), 'That file should exist prior to termination of backup process.');
39
40
        $eventDispatcher->dispatch(BackupEvent::TERMINATE, new BackupEvent(new NullProfile()));
41
42
        $this->assertFalse(file_exists($files[0]->getPath()), 'That file should not exist after termination of backup process.');
43
    }
44
45
    /**
46
     * @test
47
     *
48
     * @expectedException \RunOpenCode\Backup\Exception\SourceException
49
     */
50 View Code Duplication
    public function connectionError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $settings = require_once __DIR__ .'/../Fixtures/config/mysqldump.php';
53
        $source = new MySqlDump($settings['database'], $settings['username'], $settings['password'], 'www.non-existing-domain.com', $settings['port']);
54
55
        $source->setLogger(new NullLogger());
56
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
57
58
        $source->fetch();
59
    }
60
61
    /**
62
     * @test
63
     *
64
     * @expectedException \RunOpenCode\Backup\Exception\SourceException
65
     */
66 View Code Duplication
    public function databaseError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $settings = require_once __DIR__ .'/../Fixtures/config/mysqldump.php';
69
        $source = new MySqlDump('There is no way that you have database with this name.', $settings['username'], $settings['password'], $settings['host'], $settings['port']);
70
71
        $source->setLogger(new NullLogger());
72
        $source->setEventDispatcher($eventDispatcher = new EventDispatcher());
73
74
        $source->fetch();
75
    }
76
}