public function testHideAndShow() { $tool = ToolTestUtil::getCursorToolInstance(); $output = new PipedOutputStream(); $buffer = new \Threaded(); $monitor = new PipedInputStream($buffer, $output); $terminal = $tool->getTerminal(); $terminal->setOutput($output); $tool->hide(); $monitor->read($bytes, 6); $this->assertEquals("[?25l", $bytes); $tool->show(); $monitor->read($bytes, 9); $this->assertEquals("[?12;25h", $bytes); }
/** * Writes data to a piped output stream, when the buffer of its downstream * is full. * * The producer thread is blocked first. This can be confirmed by checking * the 'waiting' status of the downstream object. * * To wake up the producer thread, a byte is shifted out of the buffer and * the downstream is notified. * * Finally, check the 'waiting' status again to confirm the producer thread * has completed its job. */ public function testOutputWhenBufferIsFull() { // Initializes a piped input stream. $downstream = new PipedInputStream(); // Initializes buffer and fills it up with '*'. $buffer = $downstream->buffer; for ($i = 0; $i < PipedInputStream::BUFFER_SIZE; $i++) { $buffer[] = '*'; } $data = '*'; // Initializes a piped output stream. $output = new PipedOutputStream($downstream); // Initializes a producer. $producer = new Producer($output, $data); // Starts the producer. Because buffer is full, the thread will wait. $producer->start(); // Shifts one byte off the buffer and notify the thread. $downstream->synchronized(function () { $buffer = $this->buffer; $buffer->shift(); $this->notify(); }); // Waits for the thread to finish its job. $producer->join(); $this->assertTrue(true); // Now asserts the thread is not waiting. $this->assertFalse($downstream->isRunning()); }
/** * @expectedException ZerusTech\Component\IO\Exception\IOException * @expectedExceptionMessage mark/reset not supported. */ public function testMiscMethods() { $upstream = new PipedOutputStream(); $input = new PipedInputStream($upstream); $input->buffer = []; $this->assertEquals(0, $input->available()); $this->assertSame($input, $input->mark(100)); $this->assertFalse($input->markSupported()); $input->buffer[] = '*'; $input->buffer[] = '*'; $input->buffer[] = '*'; $input->buffer[] = '*'; $input->buffer[] = '*'; $this->assertEquals(5, $input->skip(5)); $this->assertFalse($input->isClosed()); $input->close(); $this->assertTrue($input->isClosed()); $input->reset(); }
/** * @dataProvider dataForTestColorize */ public function testColorize($color, $cmd, $index, $type) { $reflection = new \ReflectionClass($this->screenToolFQN); $method = $reflection->getMethod('colorize'); $method->setAccessible(true); $tool = ToolTestUtil::getScreenToolInstance(); $output = new PipedOutputStream(); $buffer = new \Threaded(); $monitor = new PipedInputStream($buffer, $output); $terminal = $tool->getTerminal(); $terminal->setOutput($output); $offsets = [30, 40]; foreach ($offsets as $offset) { if ('alias' === $type) { $command = sprintf($cmd, $index + $offset); } else { $command = sprintf($cmd, 8 + $offset, $index); } $method->invokeArgs($tool, [$color, $offset]); $monitor->read($bytes, strlen($command)); $this->assertEquals($command, $bytes); } }