Test Failed
Pull Request — master (#6)
by Timon
05:44
created

BaseTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 8
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A createConnection() 0 16 1
A __destruct() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\IntegrationTest;
5
6
use Mockery;
7
use PHPUnit\Framework\TestCase;
8
use TBolier\RethinkQL\Connection\Connection;
9
use TBolier\RethinkQL\Connection\ConnectionInterface;
10
use TBolier\RethinkQL\Connection\Options;
11
use TBolier\RethinkQL\Connection\Socket\Handshake;
12
use TBolier\RethinkQL\Connection\Socket\Socket;
13
use TBolier\RethinkQL\Types\VersionDummy\Version;
14
15
class BaseTestCase extends TestCase
16
{
17
    /**
18
     * @var ConnectionInterface
19
     */
20
    protected $connection;
21
22
    protected function setUp()
23
    {
24
        Mockery::getConfiguration()->allowMockingNonExistentMethods(false);
25
26
        parent::setUp();
27
    }
28
29
    /**
30
     * @param string $name
31
     * @return ConnectionInterface
32
     */
33
    protected function createConnection(string $name): ConnectionInterface
34
    {
35
        $options = new Options(PHPUNIT_CONNECTIONS[$name]);
36
37
        $this->connection = new Connection(
38
            function () use ($options) {
39
                return new Socket(
40
                    $options
41
                );
42
            },
43
            new Handshake($options->getUser(), $options->getPassword(), Version::V1_0),
44
            $options->getDbname()
45
        );
46
47
        return $this->connection;
48
    }
49
50
    public function __destruct()
51
    {
52
        if ($this->connection->isOpenStream()) {
53
            $this->connection->close();
54
        }
55
56
        Mockery::close();
57
    }
58
}
59