1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EDouna\LaravelDBBackup\Test\Databases; |
4
|
|
|
|
5
|
|
|
use EDouna\LaravelDBBackup\Databases\MySQLDatabase; |
6
|
|
|
use Mockery as m; |
7
|
|
|
use Orchestra\Testbench\TestCase; |
8
|
|
|
|
9
|
|
|
class MySQLDatabaseTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
protected $database; |
12
|
|
|
protected $storageMock; |
13
|
|
|
protected $processHandlerMock; |
14
|
|
|
protected $testBackupFile; |
15
|
|
|
|
16
|
|
|
public function setUp(): void |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
$this->storageMock = $this->getMockBuilder('EDouna\LaravelDBBackup\Databases\Storage')->getMock(); |
21
|
|
|
$this->storageMock = m::mock('EDouna\LaravelDBBackup\Databases\Storage'); |
22
|
|
|
$this->processHandlerMock = $this->getMockBuilder('EDouna\LaravelDBBackup\ProcessHandler')->getMock(); |
23
|
|
|
$this->database = new MySQLDatabase('testDatabase', 'testUser', 'testPassword', 'testHost', '3306', $this->processHandlerMock, $this->storageMock); |
|
|
|
|
24
|
|
|
$this->testBackupFile = 'testBackupFile.sql'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function tearDown(): void |
28
|
|
|
{ |
29
|
|
|
parent::tearDown(); |
30
|
|
|
m::close(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @test |
35
|
|
|
*/ |
36
|
|
|
public function testDumpSuccess() |
37
|
|
|
{ |
38
|
|
|
$this->processHandlerMock->method('run')->willReturn(true); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($this->database->backup($this->testBackupFile)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
*/ |
46
|
|
|
public function testDumpFailure() |
47
|
|
|
{ |
48
|
|
|
$this->processHandlerMock->method('run')->willReturn(false); |
49
|
|
|
|
50
|
|
|
$this->assertFalse($this->database->backup($this->testBackupFile)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @test |
55
|
|
|
*/ |
56
|
|
|
public function testRestoreSuccess() |
57
|
|
|
{ |
58
|
|
|
$this->processHandlerMock->method('run')->willReturn(true); |
59
|
|
|
|
60
|
|
|
$this->assertTrue($this->database->restore($this->testBackupFile)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @test |
65
|
|
|
*/ |
66
|
|
|
public function testRestoreFailure() |
67
|
|
|
{ |
68
|
|
|
$this->processHandlerMock->method('run')->willReturn(false); |
69
|
|
|
|
70
|
|
|
$this->assertFalse($this->database->restore($this->testBackupFile)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @test |
75
|
|
|
*/ |
76
|
|
|
public function testDatabaseIdentifier() |
77
|
|
|
{ |
78
|
|
|
$this->assertEquals($this->database->getDatabaseIdentifier(), 'mysql'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @test |
83
|
|
|
*/ |
84
|
|
|
public function testFileExtension() |
85
|
|
|
{ |
86
|
|
|
$this->assertEquals($this->database->getFileExtension(), 'sql'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.