Example #1
0
 public function testWriteAutoCloseOn()
 {
     $value = get_test_string();
     $value_size = strlen($value);
     $stream = string_to_stream("");
     $buffer_size = 1000;
     $writer = new StringWriter($value, $stream, $buffer_size);
     $this->assertTrue(is_resource($stream));
     while ($ret = $writer->write(true)) {
     }
     $this->assertFalse(is_resource($stream));
 }
Example #2
0
 /**
  * @expectedException kamermans\Command\TerminateException
  */
 public function testTerminateFromCallback()
 {
     $value = get_test_string();
     $stream = string_to_stream($value);
     $buffer_size = 1000;
     $callback = function ($pipe, $data) {
         // Returning false tells Command to throw a TerminateException
         return false;
     };
     $reader = new CallbackReader($stream, 0, $callback, $buffer_size);
     while (!feof($stream)) {
         $reader->read();
     }
 }
Example #3
0
 public function testWriteAutoCloseOn()
 {
     $value = get_test_string();
     $value_size = strlen($value);
     $value_stream = string_to_stream($value);
     $stream = string_to_stream("");
     $buffer_size = 1000;
     $writer = new StreamWriter($value_stream, $stream, $buffer_size);
     $this->assertSame("stream", get_resource_type($stream));
     while ($ret = $writer->write(true)) {
     }
     // This works everywhere except Travis-CI, no idea why
     // $this->assertSame("Unknown", get_resource_type($stream));
 }
Example #4
0
 public function testRead()
 {
     $value = get_test_string();
     $value_size = strlen($value);
     $stream = string_to_stream($value);
     $buffer = '';
     $buffer_size = 1000;
     $reader = new StringReader($stream, 0, $buffer, $buffer_size);
     $this->assertEmpty($buffer);
     $this->assertSame(0, $reader->getBytes());
     $iterations = 0;
     $bytes = 0;
     while (!feof($stream)) {
         $iterations++;
         $bytes += $reader->read();
     }
     // Make sure we read the same number of bytes
     $this->assertSame($value_size, $bytes);
     $this->assertSame($value_size, $reader->getBytes());
     // Make sure the data is copied to the buffer and is identical
     $this->assertSame(md5($value), md5($buffer), "I/O itegrity check failed");
     $min_iterations = ceil($value_size / $buffer_size);
     $this->assertGreaterThanOrEqual($min_iterations, $iterations, "Finished reading the stream in {$iterations} iterations, but with a buffer_size of {$buffer_size} and {$value_size} bytes of data, it must have taken at least {$min_iterations} iterations");
 }
Example #5
0
 public function testCommandBinaryStdInToStdOutStream()
 {
     // NOTE: setBinary() adds the 'binary_pipes' option to proc_open()
     // but this option is not documented, and this test passes either way.
     $value = gzencode(get_test_string());
     $stream = string_to_stream($value);
     $command = Command::factory("./stdin_stream.sh")->setDirectory(__DIR__ . "/../resources")->setBinary()->argument("stdout")->run($stream);
     $this->assertSame(md5($value), md5($command->getStdOut()));
     $this->assertEmpty($command->getStdErr());
 }