PubSubTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testTopic() 0 6 1
A testSubscribe() 0 7 1
A setup() 0 12 1
1
<?php
2
namespace Opine;
3
4
use PHPUnit_Framework_TestCase;
5
use Opine\Container\Service as Container;
6
use Opine\Config\Service as Config;
7
use ArrayObject;
8
9
class PubSubTest extends PHPUnit_Framework_TestCase
10
{
11
    private $container;
12
    private $topic;
13
14
    public function setup()
15
    {
16
        $root = __DIR__.'/../public';
17
        $config = new Config($root);
18
        $config->cacheSet();
19
        $this->container = Container::instance($root, $config, $root.'/../config/containers/test-container.yml');
20
        $model = $this->container->get('pubSubModel');
21
        $model->build();
22
        $this->topic = $this->container->get('topic');
23
        $cache = $model->readDiskCache();
24
        $this->topic->cacheSet($cache);
25
    }
26
27
    public function testTopic()
28
    {
29
        $context = new ArrayObject(['abc' => 123]);
30
        $this->topic->publish('Test', $context);
31
        $this->assertTrue('def' === $context['test2']);
32
    }
33
34
    public function testSubscribe()
35
    {
36
        $this->topic->subscribe('Test', 'pubsubTest@someMethod2');
37
        $context = new ArrayObject(['www' => 123]);
38
        $this->topic->publish('Test', new ArrayObject($context));
39
        $this->assertTrue('qrs' === $context['test3']);
40
    }
41
}
42