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

MySqlDumpSourceTest::connectionError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
loc 10
rs 9.4286
cc 1
eloc 6
nc 1
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\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
}