Passed
Push — main ( edc39f...999cd0 )
by Thierry
02:03
created

ServerContext::createDatabase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
The method dropDatabase() does not exist on Lagdo\DbAdmin\Driver\Sqlite\Tests\Driver. Did you maybe mean dropDatabases()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
        $this->driver->/** @scrutinizer ignore-call */ 
123
                       dropDatabase($database);

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.

Loading history...
123
    }
124
}
125