Passed
Push — main ( d505ee...c57ead )
by Thierry
16:17 queued 09:26
created

FeatureContext::checkTheDatabaseSize()   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 1
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
use function count;
9
10
class FeatureContext implements Context
11
{
12
    /**
13
     * @var Driver
14
     */
15
    protected $driver;
16
17
    /**
18
     * @var array
19
     */
20
    protected $databases;
21
22
    /**
23
     * @var int
24
     */
25
    protected $dbSize;
26
27
    /**
28
     * The constructor
29
     */
30
    public function __construct()
31
    {
32
        $this->driver = new Driver();
33
    }
34
35
    /**
36
     * @Given The default server is connected
37
     */
38
    public function connectToTheDefaultServer()
39
    {
40
        // Nothing to do
41
    }
42
43
    /**
44
     * @When I read the database list
45
     */
46
    public function getTheDatabaseList()
47
    {
48
        $this->databases = $this->driver->databases(true);
49
    }
50
51
    /**
52
     * @Then There is :count database on the server
53
     * @Then There are :count databases on the server
54
     */
55
    public function checkTheNumberOfDatabases(int $count)
56
    {
57
        Assert::assertEquals($count, count($this->databases));
58
    }
59
60
    /**
61
     * @Then No database query is executed
62
     */
63
    public function checkThatNoDatabaseQueryIsExecuted()
64
    {
65
        $queries = $this->driver->queries();
66
        Assert::assertEquals(0, count($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->driver->realConnection = true;
83
        $this->dbSize = $this->driver->databaseSize($database);
84
        $this->driver->realConnection = false;
85
    }
86
87
    /**
88
     * @Then The size of the database is :size
89
     */
90
    public function checkTheDatabaseSize(int $size)
91
    {
92
        Assert::assertEquals($size, $this->dbSize);
93
    }
94
}
95