forked from grgk/seo-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestCase.php
46 lines (43 loc) · 1.54 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use SeoAnalyzer\Cache;
use SeoAnalyzer\HttpClient\ClientInterface;
abstract class TestCase extends PhpUnitTestCase
{
public function setUp()
{
parent::setUp();
$cache = new Cache();
$cache->adapter->clear();
}
/**
* @param string|null $response Response body content to be returned
* @return MockObject|ClientInterface
*/
public function getClientMock(string $response = null)
{
if (empty($response)) {
$response = file_get_contents(__DIR__ . '/data/test.html');
}
$stream = $this->getMockBuilder(StreamInterface::class)->disableOriginalConstructor()->getMock();
$stream->method('getContents')->willReturn($response);
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
$response->method('getBody')->willReturn($stream);
$response->method('getHeader')->with('X-Guzzle-Redirect-History')->willReturn(['redirect' => 'redirect']);
$clientMock = $this->getMockBuilder(ClientInterface::class)->getMock();
$clientMock->method('get')->willReturn($response);
return $clientMock;
}
}