Permalink
Browse files

Adding test case for the static Amqp factory class

  • Loading branch information...
1 parent 778fda2 commit 01154c3ff97a715e9bb688fb1086aa9254233dcc Jelle Henkens committed May 31, 2012
View
@@ -9,19 +9,19 @@ class CakeAmqp extends Object {
*
* @var CakeAmqpProducer
*/
- private static $__instance = null;
+ protected static $_instance = null;
/**
* Singleton factory method to get the instance of a producer
*
* @return CakeAmqpProducer
*/
public static function getInstance() {
- if (self::$__instance == null) {
- self::$__instance = new CakeAmqpProducer();
+ if (self::$_instance == null) {
+ self::$_instance = new CakeAmqpProducer();
}
- return self::$__instance;
+ return self::$_instance;
}
/**
@@ -1,6 +1,6 @@
<?php
-class AllCakeAmqpTest extends PHPUnit_Framework_TestSuite {
+class AllCakeAmqpTestsTest extends PHPUnit_Framework_TestSuite {
/**
* Suite define the tests for this suite
No changes.
@@ -2,10 +2,20 @@
App::uses('CakeAmqp', 'CakeAmqp.Lib');
+class TestCakeAmqp extends CakeAmqp {
+ public static function reset() {
+ self::$_instance = null;
+ }
+
+ public function setInstance($instance) {
+ self::$_instance = $instance;
+ }
+}
+
/**
- * CacheTest class
+ * CakeAmqpTest class
*
- * @package Cake.Test.Case.Cache
+ * @package CakeAmqp.Test.Case
*/
class CakeAmqpTest extends CakeTestCase {
@@ -24,6 +34,31 @@ public function setUp() {
* @return void
*/
public function tearDown() {
+ TestCakeAmqp::reset();
+ }
+
+/**
+ * Tests the static getInstance method
+ *
+ * @return void
+ */
+ public function testGetInstance() {
+ $result = TestCakeAmqp::getInstance();
+ $this->assertTrue($result instanceof CakeAmqpProducer);
+ }
+/**
+ * Tests the static send method
+ *
+ * @return void
+ */
+ public function testSend() {
+ $mock = $this->getMock('CakeAmqpProducer', array('send'));
+ $mock->expects($this->once())
+ ->method('send')
+ ->will($this->returnValue(true))
+ ->with('exchange', 'routing-key', array('foo' => 'bar'), array('option' => 'one'));
+ TestCakeAmqp::setInstance($mock);
+ TestCakeAmqp::send('exchange', 'routing-key', array('foo' => 'bar'), array('option' => 'one'));
}
}
No changes.
No changes.

0 comments on commit 01154c3

Please sign in to comment.