Completed
Pull Request — master (#336)
by Stefan
05:11
created

LoggerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 38
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\ShopwarePlugins\Connect;
4
5
use ShopwarePlugins\Connect\Components\Logger;
6
use Symfony\Component\Config\Definition\Exception\Exception;
7
8
class LoggerTest extends ConnectTestHelper
9
{
10
    protected $logger;
11
12
    protected function getLogger()
13
    {
14
        if (!$this->logger) {
15
            $this->logger = new Logger(Shopware()->Db());
16
        }
17
        return $this->logger;
18
    }
19
20
    public function testWriteWithException()
21
    {
22
        $logger = $this->getLogger();
23
24
        $message = 'Example Exception '.rand(1, 9999);
25
        $logger->write(true, null, new \Exception($message));
26
27
        $sql = 'SELECT id FROM s_plugin_connect_log WHERE response LIKE ?';
28
        $id = Shopware()->Db()->fetchOne($sql, array('%' . $message . '%'));
29
30
        $this->assertNotEmpty($id);
31
    }
32
33
    public function testWriteWithString()
34
    {
35
        $logger = $this->getLogger();
36
37
        $message = 'Example Message '.rand(1, 9999);
38
        $logger->write(false, null, $message);
39
40
        $sql = 'SELECT id FROM s_plugin_connect_log WHERE response = ?';
41
        $id = Shopware()->Db()->fetchOne($sql, array($message));
42
43
        $this->assertNotEmpty($id);
44
    }
45
}