-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea3f7b2
commit a823c7e
Showing
4 changed files
with
101 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Tests\Twitch\Twirp\Example; | ||
|
||
use Twirp\ErrorCode; | ||
use Twitch\Twirp\Example\TwirpError; | ||
|
||
/** | ||
* @group example | ||
*/ | ||
final class TwirpErrorTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_has_a_code() | ||
{ | ||
$error = new TwirpError('code', 'msg'); | ||
|
||
$this->assertEquals('code', $error->code()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_has_a_message() | ||
{ | ||
$error = new TwirpError('code', 'msg'); | ||
|
||
$this->assertEquals('msg', $error->msg()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_has_metadata() | ||
{ | ||
$error = new TwirpError('code', 'msg'); | ||
$error->withMeta('key', 'value'); | ||
|
||
$this->assertEquals('value', $error->meta('key')); | ||
$this->assertEquals('', $error->meta('invalid_key')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_has_a_map_of_metadata() | ||
{ | ||
$error = new TwirpError('code', 'msg'); | ||
$error->withMeta('key', 'value'); | ||
|
||
$this->assertEquals(['key' => 'value'], $error->metaMap()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_a_new_error() | ||
{ | ||
$error = TwirpError::newError(ErrorCode::Unauthenticated, 'msg'); | ||
|
||
$this->assertEquals(ErrorCode::Unauthenticated, $error->code()); | ||
$this->assertEquals('msg', $error->msg()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_an_internal_error_when_code_is_invalid() | ||
{ | ||
$error = TwirpError::newError('code', 'msg'); | ||
|
||
$this->assertEquals(ErrorCode::Internal, $error->code()); | ||
$this->assertEquals('invalid error type code', $error->msg()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_creates_an_error_from_an_exception() | ||
{ | ||
$exception = new \Exception('msg'); | ||
$error = TwirpError::errorFromException($exception); | ||
|
||
$this->assertEquals(ErrorCode::Internal, $error->code()); | ||
$this->assertEquals('msg', $error->msg()); | ||
} | ||
} |
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