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