Files
panel-pelican-dev/tests/Traits/MocksRequestException.php

32 lines
858 B
PHP
Raw Normal View History

2017-10-23 21:10:32 -05:00
<?php
2024-03-12 22:39:16 -04:00
namespace App\Tests\Traits;
2017-10-23 21:10:32 -05:00
2025-09-24 13:34:19 +02:00
use GuzzleHttp\Exception\RequestException;
use Mockery\Mock;
2017-10-23 21:10:32 -05:00
use Mockery\MockInterface;
trait MocksRequestException
{
private RequestException|Mock $exception;
2017-10-23 21:10:32 -05:00
private mixed $exceptionResponse;
2017-10-23 21:10:32 -05: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-23 21:10:32 -05:00
{
$this->getExceptionMock($abstract)->shouldReceive('getResponse')->andReturn(value($response));
2017-10-23 21:10:32 -05:00
}
/**
* Return a mocked instance of the request exception.
*/
protected function getExceptionMock(string $abstract = RequestException::class): MockInterface
2017-10-23 21:10:32 -05:00
{
2023-02-23 12:30:16 -07:00
return $this->exception ?? $this->exception = \Mockery::mock($abstract);
2017-10-23 21:10:32 -05:00
}
}