function ProcessOutputCallbackTest::testErrorOutputOnly

Tests what happens when there is error output only.

File

core/modules/package_manager/tests/src/Unit/ProcessOutputCallbackTest.php, line 33

Class

ProcessOutputCallbackTest
@covers \Drupal\package_manager\ProcessOutputCallback[[api-linebreak]] @group package_manager

Namespace

Drupal\Tests\package_manager\Unit

Code

public function testErrorOutputOnly() : void {
  $callback = new ProcessOutputCallback();
  $logger = new TestLogger();
  $callback->setLogger($logger);
  $error_text = 'What happened?';
  $callback(OutputTypeEnum::ERR, $error_text);
  $this->assertSame([
    $error_text,
  ], $callback->getErrorOutput());
  // The error should not yet be logged.
  $this->assertEmpty($logger->records);
  // There should be no output data, but calling getOutput() should log the
  // error.
  $this->assertSame([], $callback->getOutput());
  $this->assertNull($callback->parseJsonOutput());
  $this->assertTrue($logger->hasWarning($error_text));
  // Resetting the callback should clear the error buffer but the log should
  // still have the error from before.
  $callback->reset();
  $this->assertTrue($logger->hasWarning($error_text));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.