/** * Test attempting to connect a pipe to a pipe with an output already connected. */ public function testConnectingToAConnectedPipe() { // create two pipes $pipe1 = new Pipe(); $pipe2 = new Pipe(); $pipe3 = new Pipe(); // connect them $success = $pipe1->connect($pipe2); // test assertions $this->assertTrue($success, "Expecting connected pipe1 to pipe2"); $this->assertTrue($pipe1->connect($pipe3) == false, "Expecting can't connect pipe3 to pipe1"); }
/** * Constructor. * <P> * Optionally connect the output and set the parameters.</P> * * @param string $name * @param IPipeFitting $output * @param function $filter * @param object $params * @return Filter */ public function Filter($name, IPipeFitting $output = null, $filter = null, $params = null) { parent::__construct($output); $this->name = $name; $this->setFilter($filter); $this->setParams($params); }
/** * Test connecting input and output pipes to a queue. */ public function testConnectingIOPipes() { // create output pipes 1 $pipe1 = new Pipe(); $pipe2 = new Pipe(); // create queue $queue = new Queue(); // connect input fitting $connectedInput = $pipe1->connect($queue); // connect output fitting $connectedOutput = $queue->connect($pipe2); // test assertions $this->assertTrue($pipe1 instanceof Pipe, "Expecting \$pipe1 instanceof Pipe"); $this->assertTrue($pipe2 instanceof Pipe, "Expecting \$pipe2 instanceof Pipe"); $this->assertTrue($queue instanceof Queue, "Expecting \$queue instanceof Queue"); $this->assertTrue($connectedInput, "Expecting connected input"); $this->assertTrue($connectedOutput, "Expecting connected output"); }
/** * Test receiving a message from a pipe using a PipeListener. */ public function testReceiveMessageViaPipeListener() { // create a message with complete constructor args $messageToSend = new Message(Message::NORMAL, (object) array('testProp' => 'testval'), simplexml_load_string('<testMessage testAtt="Hello" testAtt2="world"/>'), Message::PRIORITY_HIGH); // create pipe and listener $pipe = new Pipe(); $listener = new PipeListener($this, 'callBackMethod'); // connect the listener to the pipe and write the message $connected = $pipe->connect($listener); $written = $pipe->write($messageToSend); // test assertions $this->assertTrue($pipe instanceof Pipe, "Expecting pipe is Pipe"); $this->assertTrue($connected, "Expecting successfully connected listener to pipe"); $this->assertTrue($written, "Expecting wrote message to pipe"); $this->assertTrue($this->messagesReceived instanceof Message, "Expecting \$this->messagesReceived instance of Message"); $this->assertTrue($this->messagesReceived->getType() == Message::NORMAL, "Expecting \$this->messagesReceived->getType() == Message::NORMAL"); $this->assertTrue($this->messagesReceived->getHeader()->testProp == 'testval', "Expecting \$this->messagesReceived->getHeader()->testProp == 'testval'"); $this->assertTrue($this->messagesReceived->getBody()->attributes()->testAtt == 'Hello', "Expecting \$this->messagesReceived->getBody()->attributes()->testAtt == 'Hello'"); $this->assertTrue($this->messagesReceived->getPriority() == Message::PRIORITY_HIGH, "Expecting \$this->messagesReceived->getPriority() == Message::PRIORITY_HIGH"); }
/** * Test connecting input and output pipes to a filter as well as disconnecting the output. */ public function testConnectingAndDisconnectingIOPipes() { // create output pipes 1 $pipe1 = new Pipe(); $pipe2 = new Pipe(); // create filter $filter = new Filter('TestFilter'); // connect input fitting $connectedInput = $pipe1->connect($filter); // connect output fitting $connectedOutput = $filter->connect($pipe2); // test assertions $this->assertTrue($pipe1 instanceof Pipe, "Expecting pipe1 instanceof Pipe"); $this->assertTrue($pipe2 instanceof Pipe, "Expecting pipe2 instanceof Pipe"); $this->assertTrue($filter instanceof Filter, "Expecting filter instanceof Filter"); $this->assertTrue($connectedInput, "Expecting connected input"); $this->assertTrue($connectedOutput, "Expecting connected output"); // disconnect pipe 2 from filter $disconnectedPipe = $filter->disconnect(); $this->assertTrue($disconnectedPipe === $pipe2, "Expecting disconnected pipe2 from filter"); }
$data = array(); $clientIP = $_SERVER['REMOTE_ADDR']; $data['country'] = $geoservice->countryFromIP($clientIP); $data['geo'] = $geoservice->geoFromIP($clientIP); $response = $data; } else { if (DiscoUtils::route('get', '^/pipe/([a-z0-9\\-_]+)$', $parameters, $body)) { $response = $store->getPipe($parameters[1]); unset($response['_id']); } else { if (DiscoUtils::route('get', '^/pipe/([a-z0-9\\-_]+)/disco$', $parameters, $body)) { $c = $store->getPipe($parameters[1]); if ($c === null) { echo "not found pipe " . $parameters[1]; } $pipe = Pipe::fromDB($c); $query = $pipe->getQuery(); $response = $store->getIdPs($query); // $response = $query; // $response = $store->getFeed($parameters[1]); } else { if (DiscoUtils::route('get', '^/feed/([a-z0-9\\-_]+)/disco$', $parameters, $body)) { $response = $store->getFeed($parameters[1]); } else { if (DiscoUtils::route('get', '^/feed/([a-z0-9\\-_]+)/metadata$', $parameters, $body)) { $response = $store->getFeedMetadata($parameters[1]); } else { if (DiscoUtils::route('get', '^/apps$', $parameters, $body)) { $response = array('foo' => 'bar'); } else { if (DiscoUtils::route('get', '^/logo$', $parameters, $qs)) {
public function Queue(IPipeFitting $output = null) { parent::__construct($output); }
/** * Test receiving messages from two pipes using a TeeMerge. */ public function testReceiveMessagesFromTwoTeeSplitOutputs() { $this->messagesReceived = array(); // create a message to send on pipe 1 $message = new Message(Message::NORMAL, array('testProp' => 1)); // create output pipes 1 and 2 $pipe1 = new Pipe(); $pipe2 = new Pipe(); // create and connect anonymous listeners $connected1 = $pipe1->connect(new PipeListener($this, 'callBackMethod')); $connected2 = $pipe2->connect(new PipeListener($this, 'callBackMethod')); // create splitting tee (args are first two output fittings of tee) $teeSplit = new TeeSplit($pipe1, $pipe2); // write messages to their respective pipes $written = $teeSplit->write($message); // test $this->assertions $this->assertTrue($message instanceof IPipeMessage, "Expecting \$message instanceof IPipeMessage"); $this->assertTrue($pipe1 instanceof Pipe, "Expecting \$pipe1 instanceof Pipe"); $this->assertTrue($pipe2 instanceof Pipe, "Expecting \$pipe2 instanceof Pipe"); $this->assertTrue($teeSplit instanceof TeeSplit, "Expecting \$teeSplit instanceof TeeSplit"); $this->assertTrue($connected1, "Expecting connected anonymous listener to pipe 1"); $this->assertTrue($connected2, "Expecting connected anonymous listener to pipe 2"); $this->assertTrue($written, "Expecting wrote single message to tee"); // test that both messages were received, then test // FIFO order by inspecting the messages themselves $this->assertTrue(count($this->messagesReceived) == 2, "Expecting received 2 messages"); // test message 1 $this->assertions $message1 = array_shift($this->messagesReceived); $this->assertTrue($message1 instanceof IPipeMessage, "Expecting \$message1 instanceof IPipeMessage"); $this->assertTrue($message1 === $message, "Expecting \$message1 === \$pipe1Message"); // object equality // test message 2 $this->assertions $message2 = array_shift($this->messagesReceived); $this->assertTrue($message2 instanceof IPipeMessage, "Expecting \$message1 instanceof IPipeMessage"); $this->assertTrue($message2 === $message, "Expecting \$message1 === \$pipe1Message"); // object equality }
function testSaveCreatedWithCustomField() { //Defaults to = updated Pipe::initialise(function ($cfg) { $cfg->connection(DSN); $cfg->created_field = 'created_on'; }); $field = Pipe::table('test_save_fields_custom'); $field->name = 'new_name'; $field->save(); //Check created timestamp entered $id = $field->id; $field->clear(); $field->get_by_id($id); $this->assertIdentical($field->name, "new_name"); $this->assertTrue($field->created_on > 0); $field->delete(); }
/** * Test using sendMessage on an OUTPUT pipe. * <P> * Creates a Pipe, Junction and Message. * Adds the PipeListener to the Pipe. * Adds the Pipe to the Junction as an OUTPUT pipe. * uses the Junction's sendMessage method to send * the Message, then checks that it was received.</P> */ public function testSendMessageOnAnOutputPipe() { // create pipe $pipe = new Pipe(); // add a PipeListener manually $listenerAdded = $pipe->connect(new PipeListener($this, 'callBackMethod')); // create junction $junction = new Junction(); // create test message $message = new Message(Message::NORMAL, array('testVal' => 1)); // register the pipe with the junction, giving it a name and direction $registered = $junction->registerPipe('testOutputPipe', Junction::OUTPUT, $pipe); // send the message using the Junction's method // it should show up in messageReceived property via the pipeListener $sent = $junction->sendMessage('testOutputPipe', $message); // test assertions $this->assertTrue($pipe instanceof Pipe, "Expecting \$pipe instanceof Pipe"); $this->assertTrue($junction instanceof Junction, "Expecting \$junction instanceof Junction"); $this->assertTrue($registered, "Expecting regsitered pipe"); $this->assertTrue($listenerAdded, "Expecting added pipeListener"); $this->assertTrue($sent, "Expecting successful write to pipe"); $this->assertTrue(count($this->messagesReceived) == 1, "Expecting received 1 messages"); $this->assertTrue(array_pop($this->messagesReceived) === $message, "Expecting received message was same instance sent"); //object equality }
function testInitialiseWithStringNotClosure() { Pipe::initialise(DSN); $dsn = Pipe\Config::instance()->connection(); $this->assertIdentical($dsn, DSN); }
/** * remove the queue resource * * @return bool */ public function remove() { $this->pipe->close(); $this->pipe->remove(); }
function testPDOCreated() { Pipe::initialise(function ($cfg) { $cfg->connection(DSN); }); $instance = Pipe\Connection::instance(); $this->assertIsA($instance->pdo, 'PDO'); }
/** * Test receiving messages from four pipes using a TeeMerge. */ public function testReceiveMessagesFromFourPipesViaTeeMerge() { // create a message to send on pipe 1 $pipe1Message = new Message(Message::NORMAL, (object) array('testProp' => 1)); $pipe2Message = new Message(Message::NORMAL, (object) array('testProp' => 2)); $pipe3Message = new Message(Message::NORMAL, (object) array('testProp' => 3)); $pipe4Message = new Message(Message::NORMAL, (object) array('testProp' => 4)); // create pipes 1, 2, 3 and 4 $pipe1 = new Pipe(); $pipe2 = new Pipe(); $pipe3 = new Pipe(); $pipe4 = new Pipe(); // create merging tee $teeMerge = new TeeMerge($pipe1, $pipe2); $connectedExtraInput3 = $teeMerge->connectInput($pipe3); $connectedExtraInput4 = $teeMerge->connectInput($pipe4); // create listener $listener = new PipeListener($this, 'callBackMethod'); // connect the listener to the tee and write the messages $connected = $teeMerge->connect($listener); // write messages to their respective pipes $pipe1written = $pipe1->write($pipe1Message); $pipe2written = $pipe2->write($pipe2Message); $pipe3written = $pipe3->write($pipe3Message); $pipe4written = $pipe4->write($pipe4Message); // test assertions $this->assertTrue($pipe1Message instanceof IPipeMessage, "Expecting \$pipe1Message instanceof IPipeMessage"); $this->assertTrue($pipe2Message instanceof IPipeMessage, "Expecting \$pipe2Message instanceof IPipeMessage"); $this->assertTrue($pipe3Message instanceof IPipeMessage, "Expecting \$pipe3Message instanceof IPipeMessage"); $this->assertTrue($pipe4Message instanceof IPipeMessage, "Expecting \$pipe4Message instanceof IPipeMessage"); $this->assertTrue($pipe1 instanceof Pipe, "Expecting \$pipe1 instanceof Pipe"); $this->assertTrue($pipe2 instanceof Pipe, "Expecting \$pipe2 instanceof Pipe"); $this->assertTrue($pipe3 instanceof Pipe, "Expecting \$pipe3 instanceof Pipe"); $this->assertTrue($pipe4 instanceof Pipe, "Expecting \$pipe4 instanceof Pipe"); $this->assertTrue($teeMerge instanceof TeeMerge, "Expecting teeMerge instanceof TeeMerge"); $this->assertTrue($listener instanceof PipeListener, "Expecting listener instanceof PipeListener"); $this->assertTrue($connected, "Expecting connected listener to merging tee"); $this->assertTrue($connectedExtraInput3, "Expecting connected extra input \$pipe3 to merging tee"); $this->assertTrue($connectedExtraInput4, "Expecting connected extra input \$pipe4 to merging tee"); $this->assertTrue($pipe1written, "Expecting wrote message to pipe 1"); $this->assertTrue($pipe2written, "Expecting wrote message to pipe 2"); $this->assertTrue($pipe3written, "Expecting wrote message to pipe 3"); $this->assertTrue($pipe4written, "Expecting wrote message to pipe 4"); // test that both messages were received, then test // FIFO order by inspecting the messages themselves $this->assertTrue(count($this->messagesReceived) == 4, "Expecting received 4 messages"); // test message 1 assertions $message1 = array_shift($this->messagesReceived); $this->assertTrue($message1 instanceof IPipeMessage, "Expecting \$message1 instanceof IPipeMessage"); $this->assertTrue($message1 === $pipe1Message, "Expecting \$message1 === \$pipe1Message"); // object equality $this->assertTrue($message1->getType() == Message::NORMAL, "Expecting \$message1->getType() == Message::NORMAL"); $this->assertTrue($message1->getHeader()->testProp == 1, "Expecting \$message1->getHeader()->testProp == 1"); // test message 2 assertions $message2 = array_shift($this->messagesReceived); $this->assertTrue($message2 instanceof IPipeMessage, "Expecting \$message2 instanceof IPipeMessage"); $this->assertTrue($message2 === $pipe2Message, "Expecting \$message2 === \$pipe2Message"); // object equality $this->assertTrue($message2->getType() == Message::NORMAL, "Expecting \$message2->getType() == Message::NORMAL"); $this->assertTrue($message2->getHeader()->testProp == 2, "Expecting \$message2->getHeader()->testProp == 2"); // test message 3 assertions $message3 = array_shift($this->messagesReceived); $this->assertTrue($message3 instanceof IPipeMessage, "Expecting \$message3 instanceof IPipeMessage"); $this->assertTrue($message3 === $pipe3Message, "Expecting \$message3 === \$pipe3Message"); // object equality $this->assertTrue($message3->getType() == Message::NORMAL, "Expecting \$message3->getType() == Message::NORMAL"); $this->assertTrue($message3->getHeader()->testProp == 3, "Expecting \$message3->getHeader()->testProp == 3"); // test message 4 assertions $message4 = array_shift($this->messagesReceived); $this->assertTrue($message4 instanceof IPipeMessage, "Expecting \$message4 instanceof IPipeMessage"); $this->assertTrue($message4 === $pipe4Message, "Expecting \$message4 === \$pipe4Message"); // object equality $this->assertTrue($message4->getType() == Message::NORMAL, "Expecting \$message4->getType() == Message::NORMAL"); $this->assertTrue($message4->getHeader()->testProp == 4, "Expecting \$message4->getHeader()->testProp == 4"); }
public function rewind() { $this->input->rewind(); }