From d8e62a4776ec50f10b872ce527f2171e617cafad Mon Sep 17 00:00:00 2001 From: Ryan Mahoney Date: Sat, 10 Jan 2015 21:49:04 -0500 Subject: [PATCH] fix tests --- composer.json | 5 +++-- config/containers/package-container.yml | 12 ++++++++---- config/containers/test-container.yml | 5 +++-- src/Topic.php | 15 ++++++--------- tests/PubSubTest.php | 11 +++++------ tests/bootstrap.php | 1 + 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 0c238a2..d7aae49 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -32,5 +33,5 @@ "Opine\\PubSub\\": "src/" } }, - "version": "2.0.8" + "version": "2.0.9" } \ No newline at end of file diff --git a/config/containers/package-container.yml b/config/containers/package-container.yml index eb179c4..5134250 100644 --- a/config/containers/package-container.yml +++ b/config/containers/package-container.yml @@ -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' diff --git a/config/containers/test-container.yml b/config/containers/test-container.yml index d90f895..2b314b9 100644 --- a/config/containers/test-container.yml +++ b/config/containers/test-container.yml @@ -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: diff --git a/src/Topic.php b/src/Topic.php index 220cada..ac1a9f1 100644 --- a/src/Topic.php +++ b/src/Topic.php @@ -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) @@ -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; } diff --git a/tests/PubSubTest.php b/tests/PubSubTest.php index ba491a6..abab07c 100644 --- a/tests/PubSubTest.php +++ b/tests/PubSubTest.php @@ -6,8 +6,6 @@ use Opine\Config\Service as Config; use ArrayObject; -require __DIR__.'/SomeClass.php'; - class PubSubTest extends PHPUnit_Framework_TestCase { private $container; @@ -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']); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d59b286..0e4b5d6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,4 @@