コード例 #1
0
 /**
  * Closes a connected piped output stream. A listener is registered at
  * 'close.notify.before', so when the listener is called, we know the
  * downstream is notified.
  */
 public function testClose()
 {
     // 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 the listener.
     $listener = [new MarkerListener(), 'mark'];
     // Adds the dispacher and listener to the piped output stream.
     $output->setEventDispatcher($dispatcher)->addListener($output::EVENT_CLOSE_NOTIFY_BEFORE, $listener);
     // Closes the piped output stream.
     $output->close();
     // Asserts the stream has been closed.
     $this->assertTrue($output->isClosed());
     // Asserts notify() method of the piped input stream has been called.
     $this->assertSame($listener[0], $listener[0]->markers[0]);
 }