Пример #1
0
 /**
  * Test that the correct actions are registered based on the auth level
  */
 public function test_auth_level_logged_out_only()
 {
     $async = new Async(false);
     WP_Mock::expectActionAdded('async', array($async, 'launch'), 10, 20);
     WP_Mock::expectActionAdded('admin_post_nopriv_wp_async_async', array($async, 'handle_postback'));
     $async->__construct(WP_Async_Task::LOGGED_OUT);
     $this->assertConditionsMet();
 }
Пример #2
0
 /**
  * @param string $command
  * @throws ProcessStartException
  */
 public function __construct($command)
 {
     //Create output and error streams that do not block after a certain size,
     //allowing the launched process to run to completion without waiting for
     //PHP to empty it's buffers.
     $stdoutTempStream = \fopen('php://temp' . self::$maxStreamMemory, 'rw');
     if ($stdoutTempStream === false) {
         throw new ProcessStartException('Unable to open temporary stream for process standard in');
     }
     $this->pipes[] = $stdoutTempStream;
     $stderrTempStream = \fopen('php://temp' . self::$maxStreamMemory, 'rw');
     if ($stdoutTempStream === false) {
         throw new ProcessStartException('Unable to open temporary stream for process standard out');
     }
     $this->pipes[] = $stderrTempStream;
     $pipes = [];
     try {
         $this->process = \proc_open($command, [0 => ['pipe', 'r'], 1 => $stdoutTempStream, 2 => $stderrTempStream], $pipes, null, null, ['bypass_shell' => true]);
         if ($this->process === false || \is_resource($this->process) !== true) {
             throw new ProcessStartException('Unable to start process');
         }
     } catch (\ErrorException $e) {
         $matches = [];
         $match = \preg_match('`(?<=CreateProcess failed, error code - )\\d+`u', $e->getMessage(), $matches);
         if ($match === 1) {
             throw new ProcessStartException('Unable to start process, Windows error ' . $matches[0] . '. See http://msdn.microsoft.com/en-us/library/ms681381.aspx');
         } else {
             throw new ProcessStartException('Unable to start process');
         }
     }
     //$pipes[0] is the standard input stream created by \proc_open
     $pipes[1] = $stdoutTempStream;
     $pipes[2] = $stderrTempStream;
     $this->pipes = $pipes;
     parent::__construct(function () {
         return \proc_get_status($this->process)['running'] !== true;
     }, function () {
         $this->closeStdIn();
         return (new \Yasca\Core\IteratorBuilder())->from($this->pipes)->select(static function ($pipe, $index) {
             $success = \rewind($pipe);
             if ($success === false) {
                 throw new \Exception("Unable to rewind process pipe {$index}");
             }
             return $pipe;
         })->select(static function ($pipe, $index) {
             $contents = \stream_get_contents($pipe);
             if ($contents === false) {
                 throw new \Exception("Unable to get process data from process pipe {$index}");
             }
             return $contents;
         })->toArray();
     });
     $this->whenDone([$this, 'close']);
 }