1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SteamMarketProviders\ParserManager\Tests\Http; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use SteamMarketProviders\ParserManager\Contract\StrategyInterface; |
9
|
|
|
use SteamMarketProviders\ParserManager\Exception\InvalidArgumentException; |
10
|
|
|
use SteamMarketProviders\ParserManager\Http\Http; |
11
|
|
|
use SteamMarketProviders\ParserManager\Http\Options; |
12
|
|
|
use SteamMarketProviders\ParserManager\Http\Response; |
13
|
|
|
use SteamMarketProviders\ParserManager\Http\Strategy\GuzzleStrategy; |
14
|
|
|
|
15
|
|
|
class HttpTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
private readonly Http $http; |
18
|
|
|
private StrategyInterface $strategy; |
19
|
|
|
|
20
|
|
|
public function setUp(): void |
21
|
|
|
{ |
22
|
|
|
$this->http = new Http(); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$this->strategy = new class () implements StrategyInterface { |
25
|
|
|
public function __construct(?Options $options = null) |
26
|
|
|
{ |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function sendRequest(string $url): Response |
30
|
|
|
{ |
31
|
|
|
} |
|
|
|
|
32
|
|
|
}; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testSetUrl(): void |
36
|
|
|
{ |
37
|
|
|
$result = $this->http->setUrl("https://steamcommunity.com/market/listings/730/AWP%20%7C%20Phobos%20%28Field-Tested%29/render?start=0&count=1¤cy=1&format=json"); |
38
|
|
|
$this->assertInstanceOf(Http::class, $result); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testFailureSetUrl(): void |
42
|
|
|
{ |
43
|
|
|
$url = "https://steamcommunity.com/market/listings/730/Awp Dragon lord/render?start=0&count=1¤cy=1&format=json"; |
44
|
|
|
|
45
|
|
|
$this->expectException(InvalidArgumentException::class); |
46
|
|
|
$this->expectExceptionMessage('The url: "https://steamcommunity.com/market/listings/730/Awp Dragon lord/render?start=0&count=1¤cy=1&format=json" is not in a valid format'); |
47
|
|
|
|
48
|
|
|
$this->http->setUrl($url); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testDefaultStrategy(): void |
52
|
|
|
{ |
53
|
|
|
$this->assertInstanceOf(GuzzleStrategy::class, $this->http->getStrategy()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSetStrategy(): void |
57
|
|
|
{ |
58
|
|
|
$this->http->setStrategy($this->strategy); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf(StrategyInterface::class, $this->http->getStrategy()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSendRequestWhenUrlIsNotSet(): void |
64
|
|
|
{ |
65
|
|
|
$this->expectExceptionMessage('Typed property SteamMarketProviders\ParserManager\Http\Http::$url must not be accessed before initialization'); |
66
|
|
|
$this->http->sendRequest(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|