misc_pterodactyl-panel/tests/Traits/MocksRequestException.php

33 lines
878 B
PHP
Raw Permalink Normal View History

2017-10-24 02:10:32 +00:00
<?php
namespace Pterodactyl\Tests\Traits;
2017-10-24 02:10:32 +00:00
use Mockery;
use Mockery\Mock;
2017-10-24 02:10:32 +00:00
use Mockery\MockInterface;
use GuzzleHttp\Exception\RequestException;
trait MocksRequestException
{
private RequestException|Mock $exception;
2017-10-24 02:10:32 +00:00
private mixed $exceptionResponse;
2017-10-24 02:10:32 +00:00
/**
* Configure the exception mock to work with the Panel's default exception
* handler actions.
*/
protected function configureExceptionMock(string $abstract = RequestException::class, $response = null): void
2017-10-24 02:10:32 +00:00
{
$this->getExceptionMock($abstract)->shouldReceive('getResponse')->andReturn(value($response));
2017-10-24 02:10:32 +00:00
}
/**
* Return a mocked instance of the request exception.
*/
protected function getExceptionMock(string $abstract = RequestException::class): MockInterface
2017-10-24 02:10:32 +00:00
{
return $this->exception ?? $this->exception = Mockery::mock($abstract);
2017-10-24 02:10:32 +00:00
}
}