2017-03-24 23:49:31 +03:00
|
|
|
<?php
|
2017-10-12 11:13:20 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-03-24 23:49:31 +03:00
|
|
|
namespace ShlinkioTest\Shlink\Common\Util;
|
|
|
|
|
|
|
|
use Prophecy\Argument;
|
|
|
|
use Prophecy\Prophet;
|
|
|
|
use Psr\Http\Message\RequestInterface;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
2018-03-26 20:02:41 +03:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
2017-03-24 23:49:31 +03:00
|
|
|
use Zend\Diactoros\Response;
|
|
|
|
|
|
|
|
class TestUtils
|
|
|
|
{
|
|
|
|
private static $prophet;
|
|
|
|
|
2019-08-01 20:49:54 +03:00
|
|
|
public static function createReqHandlerMock(?ResponseInterface $response = null, ?RequestInterface $request = null)
|
2017-03-24 23:49:31 +03:00
|
|
|
{
|
|
|
|
$argument = $request ?: Argument::any();
|
2018-03-26 20:02:41 +03:00
|
|
|
$delegate = static::getProphet()->prophesize(RequestHandlerInterface::class);
|
|
|
|
$delegate->handle($argument)->willReturn($response ?: new Response());
|
2017-03-24 23:49:31 +03:00
|
|
|
|
|
|
|
return $delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Prophet
|
|
|
|
*/
|
|
|
|
private static function getProphet()
|
|
|
|
{
|
|
|
|
if (static::$prophet === null) {
|
|
|
|
static::$prophet = new Prophet();
|
|
|
|
}
|
|
|
|
|
|
|
|
return static::$prophet;
|
|
|
|
}
|
|
|
|
}
|