Passed
Push — main ( 999cd0...8ad049 )
by Thierry
02:25
created

ServerContext::checkThatTheOperationHasFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
     * @var bool
27
     */
28
    protected $dbResult;
29
30
    /**
31
     * The constructor
32
     */
33
    public function __construct()
34
    {
35
        $this->driver = new Driver();
36
    }
37
38
    /**
39
     * @Given The default server is connected
40
     */
41
    public function connectToTheDefaultServer()
42
    {
43
        // Nothing to do
44
        $this->driver->createConnection();
45
    }
46
47
    /**
48
     * @When I read the database list
49
     */
50
    public function getTheDatabaseList()
51
    {
52
        $this->databases = $this->driver->databases(true);
53
    }
54
55
    /**
56
     * @Then There is :count database on the server
57
     * @Then There are :count databases on the server
58
     */
59
    public function checkTheNumberOfDatabases(int $count)
60
    {
61
        Assert::assertEquals('', $this->driver->error());
62
        Assert::assertEquals($count, count($this->databases));
63
    }
64
65
    /**
66
     * @Then :count database query is executed
67
     * @Then :count database queries are executed
68
     */
69
    public function checkTheNumberOfDatabaseQueries(int $count)
70
    {
71
        Assert::assertEquals($count, count($this->driver->queries()));
72
    }
73
74
    /**
75
     * @Given The next request returns :status
76
     */
77
    public function setTheNextDatabaseRequestStatus(bool $status)
78
    {
79
        $this->driver->connection()->setNextResultStatus($status);
80
    }
81
82
    /**
83
     * @When I read the database :database size
84
     */
85
    public function getTheDatabaseSize(string $database)
86
    {
87
        $this->dbSize = $this->driver->databaseSize($database);
88
    }
89
90
    /**
91
     * @Then The size of the database is :size
92
     */
93
    public function checkTheDatabaseSize(int $size)
94
    {
95
        Assert::assertEquals($size, $this->dbSize);
96
    }
97
98
    /**
99
     * @When I create the database :database
100
     */
101
    public function createDatabase(string $database)
102
    {
103
        $this->dbResult = $this->driver->createDatabase($database, '');
104
    }
105
106
    /**
107
     * @When I open the database :database
108
     */
109
    public function openDatabase(string $database)
110
    {
111
        $this->driver->connect($database, '');
112
    }
113
114
    /**
115
     * @When I rename the database to :database
116
     */
117
    public function renameDatabase(string $database)
118
    {
119
        $this->dbResult = $this->driver->renameDatabase($database, '');
120
    }
121
122
    /**
123
     * @When I delete the database :database
124
     */
125
    public function deleteDatabase(string $database)
126
    {
127
        $this->dbResult = $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

127
        /** @scrutinizer ignore-call */ 
128
        $this->dbResult = $this->driver->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...
128
    }
129
130
    /**
131
     * @Then The operation has succeeded
132
     */
133
    public function checkThatTheOperationHasSucceeded()
134
    {
135
        Assert::assertTrue($this->dbResult);
136
    }
137
138
    /**
139
     * @Then The operation has failed
140
     */
141
    public function checkThatTheOperationHasFailed()
142
    {
143
        Assert::assertFalse($this->dbResult);
144
    }
145
}
146