Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-mahoney committed Jan 11, 2015
1 parent 34fadf4 commit d8e62a4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"opine/interfaces": "~1.0",
"opine/bundle" : "~2.0",
"opine/config" : "~3.0",
"opine/container" : "~2.0"
"opine/container" : "~2.0",
"opine/route" : "~3.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.32"
Expand All @@ -32,5 +33,5 @@
"Opine\\PubSub\\": "src/"
}
},
"version": "2.0.8"
"version": "2.0.9"
}
12 changes: 8 additions & 4 deletions config/containers/package-container.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
services:
pubSubModel:
class: 'Opine\PubSub\Model'
arguments: ['%root%', '@bundleModel']
class: Opine\PubSub\Model
arguments:
- '%root%'
- '@bundleModel'
topic:
class: 'Opine\PubSub\Topic'
arguments: ['@container']
class: Opine\PubSub\Topic
arguments:
- '@route'
- '@pubSubModel'
5 changes: 3 additions & 2 deletions config/containers/test-container.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
imports:
- package-container.yml
- ../../vendpr/opine/container/config/containers/package-container.yml
- ../../vendpr/opine/bundle/config/containers/package-container.yml
- ../../vendor/opine/container/config/containers/package-container.yml
- ../../vendor/opine/bundle/config/containers/package-container.yml
- ../../vendor/opine/route/config/containers/package-container.yml

services:
pubsubTest:
Expand Down
15 changes: 6 additions & 9 deletions src/Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
use ArrayObject;
use Exception;
use Opine\Interfaces\Topic as TopicInterface;
use Opine\Interfaces\Container as ContainerInterface;
use Opine\Interfaces\Route as RouteInterface;

class Topic implements TopicInterface
{
private $topics = [];
private $container;
private $route;
private $model;

public function __construct(ContainerInterface $container)
public function __construct(RouteInterface $route, $model)
{
$this->container = $container;
$this->model = $container->get('pubSubModel');
$this->route = $route;
$this->model = $model;
}

public function cacheSet($cache)
Expand Down Expand Up @@ -88,10 +88,7 @@ public function publish($topic, ArrayObject $context)
if (substr_count($subscriber, '@') != 1) {
continue;
}
$service = explode('@', $subscriber)[0];
$method = explode('@', $subscriber)[1];
$service = $this->container->get($service);
$response = $service->$method($context);
$response = $this->route->serviceMethod($subscriber, $context);
if ($response === false) {
break;
}
Expand Down
11 changes: 5 additions & 6 deletions tests/PubSubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use Opine\Config\Service as Config;
use ArrayObject;

require __DIR__.'/SomeClass.php';

class PubSubTest extends PHPUnit_Framework_TestCase
{
private $container;
Expand All @@ -22,20 +20,21 @@ public function setup()
$model = $this->container->get('pubSubModel');
$model->build();
$this->topic = $this->container->get('topic');
$this->topic->cacheSet($model->readDiskCache());
$cache = $model->readDiskCache();
$this->topic->cacheSet($cache);
}

public function testTopic()
{
$context = ['abc' => 123];
$this->topic->publish('Test', new ArrayObject($context));
$context = new ArrayObject(['abc' => 123]);
$this->topic->publish('Test', $context);
$this->assertTrue('def' === $context['test2']);
}

public function testSubscribe()
{
$this->topic->subscribe('Test', 'pubsubTest@someMethod2');
$context = ['www' => 123];
$context = new ArrayObject(['www' => 123]);
$this->topic->publish('Test', new ArrayObject($context));
$this->assertTrue('qrs' === $context['test3']);
}
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php
date_default_timezone_set('UTC');
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/SomeClass.php';

0 comments on commit d8e62a4

Please sign in to comment.