Skip to content

Commit

Permalink
Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto M authored and sebastianbergmann committed Oct 5, 2022
1 parent e15b3ad commit 81cfbde
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
31 changes: 18 additions & 13 deletions src/Framework/Exception/AssertionFailedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,39 @@
class AssertionFailedError extends Exception implements SelfDescribing
{
/**
* @var string|null
* @var null|string
*/
protected $previousThrowableClass;

/**
* @var string|null
* @var null|int|string
*/
protected $previousThrowableMessage;
protected $previousThrowableCode;

/**
* @var int|string|null
* @var null|string
*/
protected $previousThrowableCode;
protected $previousThrowableMessage;

/**
* @var string|null
* @var null|string
*/
protected $previousThrowableTrace;

public function __construct($message = '', $code = 0, Throwable $previous = null, bool $inIsolation = false)
public function __construct(string $message = '', int $code = 0, Throwable $previous = null, bool $inIsolation = false)
{
parent::__construct($message, $code, $previous);

if ($inIsolation && $previous) {
$this->previousThrowableClass = get_class($previous);
$this->previousThrowableClass = get_class($previous);
$this->previousThrowableMessage = $previous->getMessage();
$this->previousThrowableCode = $previous->getCode();
$this->previousThrowableTrace = Filter::getFilteredStacktrace($previous);
$this->previousThrowableCode = $previous->getCode();

try {
$this->previousThrowableTrace = Filter::getFilteredStacktrace($previous);
} catch (Exception $e) {
$this->previousThrowableTrace = '';
}
}
}

Expand All @@ -55,13 +60,13 @@ public function __toString(): string
$string = parent::__toString();

if ($this->previousThrowableClass) {
$string .= "\nCaused by " . $this->previousThrowableClass;
$string .= PHP_EOL . 'Caused by ' . $this->previousThrowableClass;

if ($this->previousThrowableMessage !== '') {
$string .= ": " . $this->previousThrowableMessage;
$string .= ': ' . $this->previousThrowableMessage;
}

$string .= "\n\n" . $this->previousThrowableTrace;
$string .= PHP_EOL . PHP_EOL . $this->previousThrowableTrace;
}

return $string;
Expand Down
14 changes: 7 additions & 7 deletions tests/_files/AssertionFailedErrorChainedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;

class AssertionFailedErrorChainedTest extends TestCase
{
protected function onNotSuccessfulTest(\Throwable $t): void
{
throw new AssertionFailedError($t->getMessage(), $t->getCode(), $t, true);
parent::onNotSuccessfulTest($t);
}

/**
* @runInSeparateProcess
*/
public function testOne(): void
{
throw new \RuntimeException('foo');
}

protected function onNotSuccessfulTest(Throwable $t): void
{
throw new AssertionFailedError($t->getMessage(), $t->getCode(), $t, true);
parent::onNotSuccessfulTest($t);
}
}

0 comments on commit 81cfbde

Please sign in to comment.