|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File: ReactPHPRequestAdapterTest.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Maciej Sławik <[email protected]> |
|
6
|
|
|
* Github: https://github.com/maciejslawik |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MSlwk\Otomoto\Middleware\Test\Unit\Webpage\Adapter\ReactPHP; |
|
10
|
|
|
|
|
11
|
|
|
use MSlwk\Otomoto\Middleware\Webpage\Adapter\ReactPHP\ClientFactory; |
|
12
|
|
|
use MSlwk\Otomoto\Middleware\Webpage\Adapter\ReactPHP\ReactPHPRequestAdapter; |
|
13
|
|
|
use MSlwk\Otomoto\Middleware\Webpage\Data\UrlDTO; |
|
14
|
|
|
use MSlwk\Otomoto\Middleware\Webpage\Data\UrlDTOArray; |
|
15
|
|
|
use MSlwk\Otomoto\Middleware\Webpage\Exception\GETHandlerException; |
|
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use React\EventLoop\LoopInterface; |
|
19
|
|
|
use React\HttpClient\Client; |
|
20
|
|
|
use React\HttpClient\Request; |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ReactPHPRequestAdapterTest |
|
25
|
|
|
* @package MSlwk\Otomoto\Middleware\Test\Unit\Webpage\Adapter\ReactPHP |
|
26
|
|
|
*/ |
|
27
|
|
|
class ReactPHPRequestAdapterTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @test |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testCorrectExceptionThrownOnEmptyResult() |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var MockObject|LoopInterface $loop */ |
|
35
|
|
|
$loop = $this->getMockBuilder(LoopInterface::class) |
|
36
|
|
|
->getMock(); |
|
37
|
|
|
/** @var MockObject|ClientFactory $clientFactory */ |
|
38
|
|
|
$clientFactory = $this->getMockBuilder(ClientFactory::class) |
|
39
|
|
|
->disableOriginalConstructor() |
|
40
|
|
|
->getMock(); |
|
41
|
|
|
$client = $this->getMockBuilder(Client::class) |
|
42
|
|
|
->disableOriginalConstructor() |
|
43
|
|
|
->getMock(); |
|
44
|
|
|
$clientFactory->expects($this->any()) |
|
45
|
|
|
->method('create') |
|
46
|
|
|
->will($this->returnValue($client)); |
|
47
|
|
|
$request = $this->getMockBuilder(Request::class) |
|
48
|
|
|
->disableOriginalConstructor() |
|
49
|
|
|
->setMethods(['end']) |
|
50
|
|
|
->getMock(); |
|
51
|
|
|
$client->expects($this->once()) |
|
52
|
|
|
->method('request') |
|
53
|
|
|
->will($this->returnValue($request)); |
|
54
|
|
|
|
|
55
|
|
|
$urlDTO = new UrlDTO(''); |
|
56
|
|
|
$urlDTOArray = new UrlDTOArray($urlDTO); |
|
57
|
|
|
$adapter = new ReactPHPRequestAdapter($loop, $clientFactory); |
|
58
|
|
|
$this->expectException(GETHandlerException::class); |
|
59
|
|
|
$adapter->getWebpages($urlDTOArray); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|