Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3913584
D203.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D203.diff
View Options
diff --git a/src/BlackholeBroker.php b/src/BlackholeBroker.php
new file mode 100644
--- /dev/null
+++ b/src/BlackholeBroker.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Keruald\Broker;
+
+class BlackholeBroker extends Broker {
+ ///
+ /// Broker implementation
+ ///
+
+ /**
+ * Sends a message to the broker, which will silently discards it.
+ *
+ * @param string $message The message to send
+ */
+ public final function sendMessage ($message) {
+ return $this;
+ }
+
+ ///
+ /// Omnipotence to ease lightweight mock testing without any lib
+ ///
+
+ /**
+ * @var bool
+ */
+ private $acceptAllMethodCalls = false;
+
+ /**
+ * Configures the broker to accept every method call
+ */
+ public function acceptAllMethodCalls () {
+ $this->acceptAllMethodCalls = true;
+ return $this;
+ }
+
+ /**
+ * Handles a method overloading call
+ *
+ * @param string $name The name of the method being called
+ * @param array $arguments An enumerated array containing the parameters
+ * passed to the method
+ */
+ public function __call ($name, array $arguments) {
+ if ($this->acceptAllMethodCalls) {
+ return $this; // Brokers are intended to be fluent
+ }
+
+ throw new \BadFunctionCallException(
+ "Blackhole broker doesn't implement the $name method."
+ );
+ }
+}
diff --git a/tests/BlackholeBrokerTest.php b/tests/BlackholeBrokerTest.php
new file mode 100644
--- /dev/null
+++ b/tests/BlackholeBrokerTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Keruald\Broker\Tests;
+
+use Keruald\Broker\BlackholeBroker;
+
+class BlackholeBrokerTest extends TestCase {
+ /**
+ * @var Keruald\Broker\BlackholeBroker
+ */
+ protected $instance;
+
+ protected function setUp() {
+ $this->instance = new BlackholeBroker();
+ }
+
+ /**
+ * @expectedException \BadFunctionCallException
+ */
+ public function testNonDefaultOmnipotence () {
+ // By default, our blackhole broker shouldn't accept any method.
+ $this->instance->spreadLove();
+ }
+
+ public function testFluencyPattern () {
+ $methodsCascade = [
+ ['connect'],
+ ['sendMessage', 'lorem ipsum dolor'],
+ ['disconnect'],
+ ];
+
+ $this->instance->acceptAllMethodCalls();
+ $this->assertMethodCascading(
+ $this->instance,
+ $methodsCascade
+ );
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 10:45 (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307972
Default Alt Text
D203.diff (2 KB)
Attached To
Mode
D203: Blackhole broker implementation
Attached
Detach File
Event Timeline
Log In to Comment