Passed
Push — master ( 718618...cd6f65 )
by Vladimir
02:24
created

DbServiceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOf() 0 3 1
A testCreate() 0 13 1
A testTriggerEvent() 0 17 1
A _before() 0 4 1
1
<?php
2
/**
3
 * @link https://github.com/yiimaker/yii2-newsletter
4
 * @copyright Copyright (c) 2017 Yii Maker
5
 * @license BSD 3-Clause License
6
 */
7
8
namespace ymaker\newsletter\tests\unit\services;
9
10
use yii\base\Event;
11
use ymaker\newsletter\common\events\SubscribeEvent;
12
use ymaker\newsletter\common\models\entities\NewsletterClient;
13
use ymaker\newsletter\common\services\DbService;
14
use ymaker\newsletter\common\services\ServiceInterface;
15
use ymaker\newsletter\tests\unit\TestCase;
16
17
/**
18
 * Test case for database service
19
 *
20
 * @author Vladimir Kuprienko <[email protected]>
21
 * @since 1.0
22
 */
23
class DbServiceTest extends TestCase
0 ignored issues
show
Coding Style introduced by
The property $_service is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
24
{
25
    /**
26
     * @var DbService
27
     */
28
    private $_service;
29
30
31
    /**
32
     * @inheritdoc
33
     */
34
    protected function _before()
35
    {
36
        parent::_before();
37
        $this->_service = new DbService();
38
    }
39
40
    public function testInstanceOf()
41
    {
42
        $this->assertInstanceOf(ServiceInterface::class, $this->_service);
43
    }
44
45
    public function testCreate()
46
    {
47
        $data = [
48
            'NewsletterClient' => [
49
                'contacts' => '[email protected]'
50
            ],
51
        ];
52
53
        $res = $this->_service->create($data);
54
55
        $this->assertTrue($res);
56
        $this->tester->seeRecord(NewsletterClient::class, [
57
            'contacts' => '[email protected]'
58
        ]);
59
    }
60
61
    public function testTriggerEvent()
62
    {
63
        $contacts = '[email protected]';
64
        Event::on(
65
            DbService::class,
66
            SubscribeEvent::EVENT_AFTER_SUBSCRIBE,
67
            function (SubscribeEvent $event) use ($contacts) {
68
                $this->assertEquals($contacts, $event->contacts);
69
            }
70
        );
71
72
        $data = [
73
            'NewsletterClient' => [
74
                'contacts' => $contacts
75
            ],
76
        ];
77
        $this->_service->create($data);
78
    }
79
}
80