ManagerFactoryTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 82
c 0
b 0
f 0
wmc 3
lcom 0
cbo 4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testInsert() 0 25 1
A assertEqualsAfterDelay() 0 7 1
B getConnectors() 0 32 1
1
<?php
2
3
namespace AsyncPHP\Icicle\Cache\Test\Driver;
4
5
use AsyncPHP\Icicle\Database\ManagerFactory;
6
use Icicle\Coroutine;
7
use Icicle\Loop;
8
use PHPUnit_Framework_TestCase;
9
10
class ManagerFactoryTest extends PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @dataProvider getConnectors
14
     *
15
     * @param array $config
16
     */
17
    public function testInsert(array $config)
18
    {
19
        Coroutine\create(function () use ($config) {
20
            $factory = new ManagerFactory();
21
            $database = $factory->create($config);
22
23
            $time = time();
24
25
            yield $database
26
                ->table("test")
27
                ->insert(["text" => $time]);
28
29
            $row = (
30
            yield $database
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<AsyncPHP\Icicle\Database\Manager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
31
                ->table("test")
32
                ->select()
33
                ->where("text = ?", $time)
34
                ->first()
35
            );
36
37
            $this->assertEqualsAfterDelay(0.5, $row["text"], $time);
38
        })->done();
39
40
        Loop\run();
41
    }
42
43
    /**
44
     * @param float $delay
45
     * @param mixed $expected
46
     * @param mixed $actual
47
     */
48
    private function assertEqualsAfterDelay($delay, $expected, $actual)
49
    {
50
        Loop\timer($delay, function () use ($expected, $actual) {
51
            $this->assertEquals($expected, $actual);
52
            Loop\stop();
53
        });
54
    }
55
56
    /**
57
     * @return array
58
     */
59
    public function getConnectors()
60
    {
61
        return [
62
            [
63
                [
64
                    "connector" => "blocking",
65
                    "driver" => "mysql",
66
                    "username" => "root",
67
                    "password" => "",
68
                    "schema" => "icicle",
69
                ],
70
            ],
71
            [
72
                [
73
                    "connector" => "doorman",
74
                    "driver" => "mysql",
75
                    "username" => "root",
76
                    "password" => "",
77
                    "schema" => "icicle",
78
                    "remit" => [
79
                        "driver" => "zeromq",
80
                        "server" => [
81
                            "port" => 5555,
82
                        ],
83
                        "client" => [
84
                            "port" => 5556,
85
                        ],
86
                    ],
87
                ],
88
            ],
89
        ];
90
    }
91
}
92