-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add messages to AssertionFailedError exceptions.
- Loading branch information
Showing
7 changed files
with
77 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Zrnik\PHPUnit; | ||
|
||
use Throwable; | ||
|
||
class ThrownResult | ||
{ | ||
public string $type; | ||
public string $message; | ||
public int $code; | ||
|
||
final private function __construct( | ||
string $type, string $message, int $code | ||
) | ||
{ | ||
$this->type = $type; | ||
$this->message = $message; | ||
$this->code = $code; | ||
} | ||
|
||
public static function createFromThrowable(Throwable $throwable): ThrownResult | ||
{ | ||
return new static( | ||
static::getExceptionType($throwable), | ||
$throwable->getMessage(), | ||
$throwable->getCode() | ||
); | ||
} | ||
|
||
/** | ||
* @param Throwable $throwable | ||
* @return string | ||
*/ | ||
private static function getExceptionType(Throwable $throwable): string | ||
{ | ||
/** | ||
* As the type-check makes sure we only get 'Throwable' type, | ||
* we will never get 'false' from 'get_class' function. | ||
* | ||
* get_debug_type is better, but php 7.4 still supported. | ||
*/ | ||
return @get_class($throwable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters