1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Lagdo\DbAdmin\Driver\Sqlite\Tests\Driver; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use PHPUnit\Framework\Assert; |
7
|
|
|
|
8
|
|
|
class ServerContext implements Context |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var Driver |
12
|
|
|
*/ |
13
|
|
|
protected $driver; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $databases; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $dbSize; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The constructor |
27
|
|
|
*/ |
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
$this->driver = new Driver(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @Given The default server is connected |
35
|
|
|
*/ |
36
|
|
|
public function connectToTheDefaultServer() |
37
|
|
|
{ |
38
|
|
|
// Nothing to do |
39
|
|
|
$this->driver->createConnection(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @When I read the database list |
44
|
|
|
*/ |
45
|
|
|
public function getTheDatabaseList() |
46
|
|
|
{ |
47
|
|
|
$this->databases = $this->driver->databases(true); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @Then There is :count database on the server |
52
|
|
|
* @Then There are :count databases on the server |
53
|
|
|
*/ |
54
|
|
|
public function checkTheNumberOfDatabases(int $count) |
55
|
|
|
{ |
56
|
|
|
Assert::assertEquals('', $this->driver->error()); |
57
|
|
|
Assert::assertEquals($count, count($this->databases)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Then :count database query is executed |
62
|
|
|
* @Then :count database queries are executed |
63
|
|
|
*/ |
64
|
|
|
public function checkTheNumberOfDatabaseQueries(int $count) |
65
|
|
|
{ |
66
|
|
|
Assert::assertEquals($count, count($this->driver->queries())); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Given The next request returns :status |
71
|
|
|
*/ |
72
|
|
|
public function setTheNextDatabaseRequestStatus(bool $status) |
73
|
|
|
{ |
74
|
|
|
$this->driver->connection()->setNextResultStatus($status); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @When I read the database :database size |
79
|
|
|
*/ |
80
|
|
|
public function getTheDatabaseSize(string $database) |
81
|
|
|
{ |
82
|
|
|
$this->dbSize = $this->driver->databaseSize($database); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @Then The size of the database is :size |
87
|
|
|
*/ |
88
|
|
|
public function checkTheDatabaseSize(int $size) |
89
|
|
|
{ |
90
|
|
|
Assert::assertEquals($size, $this->dbSize); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @When I create the database :database |
95
|
|
|
*/ |
96
|
|
|
public function createDatabase(string $database) |
97
|
|
|
{ |
98
|
|
|
$this->driver->createDatabase($database, ''); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @When I open the database :database |
103
|
|
|
*/ |
104
|
|
|
public function openDatabase(string $database) |
105
|
|
|
{ |
106
|
|
|
$this->driver->connect($database, ''); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @When I rename the database to :database |
111
|
|
|
*/ |
112
|
|
|
public function renameDatabase(string $database) |
113
|
|
|
{ |
114
|
|
|
$this->driver->renameDatabase($database, ''); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @When I delete the database :database |
119
|
|
|
*/ |
120
|
|
|
public function deleteDatabase(string $database) |
121
|
|
|
{ |
122
|
|
|
$this->driver->dropDatabase($database); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.