/** * Connects a piped output stream to a piped input stream and disallows the * connect() method of the piped output stream to be called. */ public function testNonReverseConnect() { // Initializes a piped output stream $upstream = new PipedOutputStream(); // Initializes an event dispatcher $dispatcher = new EventDispatcher(); // Initializes the listener $listener = [new MarkerListener(), 'mark']; // Adds dispatcher and listener to the piped output stream. $upstream->setEventDispatcher($dispatcher)->addListener($upstream::EVENT_CONNECT_BEFORE, $listener); // Initializes a piped input stream. $input = new PipedInputStream(); // Connects the piped input stream to the piped output stream. // But sets 'reverse' to false. $input->connect($upstream, false, false); // Asserts the connect() method of the output stream has not been // called. $this->assertNull($listener[0]->markers[0]); }
/** * Writes data to a piped output stream. * A listener is listening at write.receive before event, so if the listener * is triggered, we know the receive() method of the downstream is called. */ public function testOutput() { // Initializes a piped input stream. $downstream = new PipedInputStream(); // Initializes a piped output stream. $output = new PipedOutputStream($downstream); // Initializes an event dispatcher. $dispatcher = new EventDispatcher(); // Initializes a listener. $listener = [new MarkerListener(), 'mark']; // Adds the dispatcher and listener to the piped output stream. $output->setEventDispatcher($dispatcher)->addListener($output::EVENT_WRITE_RECEIVE_BEFORE, $listener); // Writes '*' to the piped output stream. $data = '*'; $this->output->invoke($output, $data); // Asserts the receive() method of the piped input stream has been // called. $this->assertSame($listener[0], $listener[0]->markers[0]); // Asserts '*' has been written to the piped output stream. $this->assertEquals($data, implode('', array_values((array) $downstream->buffer))); }