PubSubTest::testTopic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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