/** * Closes a connected piped input stream. A listener is registered at * 'close.notify.before', so when the listener is called, we know the * upstream is notified. */ public function testClose() { // Initializes a piped output stream. $upstream = new PipedOutputStream(); // Initializes a piped input stream. $input = new PipedInputStream($upstream); // Initializes an event dispatcher. $dispatcher = new EventDispatcher(); // Initializes a listener. $listener = [new MarkerListener(), 'mark']; // Adds dispatcher and listener to the piped input stream. $input->setEventDispatcher($dispatcher)->addListener($input::EVENT_CLOSE_NOTIFY_BEFORE, $listener); // Closes the piped input stream. $input->close(); // Asserts closed is true. $this->assertTrue($input->isClosed()); // Asserts notify() of the piped input stream has been called. $this->assertSame($listener[0], $listener[0]->markers[0]); }
/** * Connects a piped output stream to a piped input stream and disallows the * connect() method of the piped input stream to be called. */ public function testNonReverseConnect() { // Initializes a piped input stream. $downstream = new PipedInputStream(); // Initializes an event dispatcher. $dispatcher = new EventDispatcher(); // Initializes a listener. $listener = [new MarkerListener(), 'mark']; // Adds the dispatcher and listener to the piped input stream. $downstream->setEventDispatcher($dispatcher)->addListener($downstream::EVENT_CONNECT_BEFORE, $listener); // Initializes a piped output stream. $output = new PipedOutputStream(); // Connects the piped output stream to the piped input stream, but sets // the 'reverse' argument to false. $output->connect($downstream, false, false); // Asserts the connect() method of the piped input stream has not been // called. $this->assertNull($listener[0]->markers[0]); }