Passed
Branch main (4c0377)
by Thierry
03:21
created

ServerContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 83
rs 10
c 1
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getTheDatabaseList() 0 3 1
A setTheNextDatabaseRequestStatus() 0 3 1
A connectToTheDefaultServer() 0 2 1
A __construct() 0 3 1
A checkTheNumberOfDatabases() 0 3 1
A getTheDatabaseSize() 0 5 1
A checkThatNoDatabaseQueryIsExecuted() 0 4 1
A checkTheDatabaseSize() 0 3 1
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
    }
40
41
    /**
42
     * @When I read the database list
43
     */
44
    public function getTheDatabaseList()
45
    {
46
        $this->databases = $this->driver->databases(true);
47
    }
48
49
    /**
50
     * @Then There is :count database on the server
51
     * @Then There are :count databases on the server
52
     */
53
    public function checkTheNumberOfDatabases(int $count)
54
    {
55
        Assert::assertEquals($count, count($this->databases));
56
    }
57
58
    /**
59
     * @Then No database query is executed
60
     */
61
    public function checkThatNoDatabaseQueryIsExecuted()
62
    {
63
        $queries = $this->driver->queries();
64
        Assert::assertEquals(0, count($queries));
65
    }
66
67
    /**
68
     * @Given The next request returns :status
69
     */
70
    public function setTheNextDatabaseRequestStatus(bool $status)
71
    {
72
        $this->driver->connection()->setNextResultStatus($status);
73
    }
74
75
    /**
76
     * @When I read the database :database size
77
     */
78
    public function getTheDatabaseSize(string $database)
79
    {
80
        $this->driver->realConnection = true;
81
        $this->dbSize = $this->driver->databaseSize($database);
82
        $this->driver->realConnection = false;
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