Skip to content

Commit

Permalink
rename errorOutput to errorLog
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Feb 7, 2025
1 parent 675ba52 commit a7110dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
private bool $outputBufferingActive = false;
private int $outputBufferingLevel;
private bool $outputRetrievedForAssertion = false;
private string $errorOutput = '';
private ?string $errorOutputExpectedRegex = null;
private ?string $errorOutputPrevious = null;
private string $errorLogOutput = '';
private ?string $errorLogExpectedRegex = null;
private ?string $errorLogPrevious = null;

/** @var null|resource */
private $errorOutputResource;
private $errorLogResource;
private bool $doesNotPerformAssertions = false;

/**
Expand Down Expand Up @@ -1012,9 +1012,9 @@ final protected function expectOutputString(string $expectedString): void
$this->outputExpectedString = $expectedString;
}

final protected function expectErrorOutputRegex(string $expectedRegex): void
final protected function expectErrorLogRegex(string $expectedRegex): void
{
$this->errorOutputExpectedRegex = $expectedRegex;
$this->errorLogExpectedRegex = $expectedRegex;
}

/**
Expand Down Expand Up @@ -1459,13 +1459,22 @@ private function startOutputBuffering(): void
$this->outputBufferingActive = true;
$this->outputBufferingLevel = ob_get_level();

$capture = tmpfile();
$this->errorOutputPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
$this->errorOutputResource = $capture;
$capture = tmpfile();
$this->errorLogPrevious = ini_set('error_log', stream_get_meta_data($capture)['uri']);
$this->errorLogResource = $capture;
}

private function stopOutputBuffering(): bool
{
if ($this->errorLogResource !== null) {
$this->errorLogOutput = stream_get_contents($this->errorLogResource);
fclose($this->errorLogResource);
}

if ($this->errorLogPrevious !== null) {
ini_set('error_log', $this->errorLogPrevious);
}

$bufferingLevel = ob_get_level();

if ($bufferingLevel !== $this->outputBufferingLevel) {
Expand All @@ -1487,15 +1496,6 @@ private function stopOutputBuffering(): bool
return false;
}

if ($this->errorOutputResource !== null) {
$this->errorOutput = stream_get_contents($this->errorOutputResource);
fclose($this->errorOutputResource);
}

if ($this->errorOutputPrevious !== null) {
ini_set('error_log', $this->errorOutputPrevious);
}

$this->output = ob_get_clean();

$this->outputBufferingActive = false;
Expand Down Expand Up @@ -1886,8 +1886,8 @@ private function performAssertionsOnOutput(): void
$this->assertMatchesRegularExpression($this->outputExpectedRegex, $this->output);
} elseif ($this->outputExpectedString !== null) {
$this->assertSame($this->outputExpectedString, $this->output);
} elseif ($this->errorOutputExpectedRegex !== null) {
$this->assertMatchesRegularExpression($this->errorOutputExpectedRegex, $this->errorOutput);
} elseif ($this->errorLogExpectedRegex !== null) {
$this->assertMatchesRegularExpression($this->errorLogExpectedRegex, $this->errorLogOutput);
}
} catch (ExpectationFailedException $e) {
$this->status = TestStatus::failure($e->getMessage());
Expand Down Expand Up @@ -2167,7 +2167,7 @@ private function isRegisteredFailure(Throwable $t): bool
*/
private function hasExpectationOnOutput(): bool
{
return is_string($this->outputExpectedString) || is_string($this->outputExpectedRegex) || is_string($this->errorOutputExpectedRegex);
return is_string($this->outputExpectedString) || is_string($this->outputExpectedRegex) || is_string($this->errorLogExpectedRegex);
}

private function requirementsNotSatisfied(): bool
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/regression/2155/Issue2155Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function testOne(): void
$foo = new Foo;

$this->assertSame('', $foo->doFoo());
$this->expectErrorOutputRegex('/logged a side effect/');
$this->expectErrorLogRegex('/logged a side effect/');
}
}

0 comments on commit a7110dc

Please sign in to comment.