1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SteamMarketProviders\ParserManager\Tests\Parser; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use PHPHtmlParser\Exceptions\ChildNotFoundException; |
9
|
|
|
use PHPHtmlParser\Exceptions\CircularException; |
10
|
|
|
use PHPHtmlParser\Exceptions\ContentLengthException; |
11
|
|
|
use PHPHtmlParser\Exceptions\LogicalException; |
12
|
|
|
use PHPHtmlParser\Exceptions\NotLoadedException; |
13
|
|
|
use PHPHtmlParser\Exceptions\StrictException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use SteamMarketProviders\Enums\SteamApp; |
16
|
|
|
use SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder; |
17
|
|
|
use SteamMarketProviders\ParserManager\Builder\SearchUrlBuilder; |
18
|
|
|
use SteamMarketProviders\ParserManager\Contract\StrategyInterface; |
19
|
|
|
use SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface; |
20
|
|
|
use SteamMarketProviders\ParserManager\Exception\HttpException; |
21
|
|
|
use SteamMarketProviders\ParserManager\Http\Options; |
22
|
|
|
use SteamMarketProviders\ParserManager\Http\Response; |
23
|
|
|
use SteamMarketProviders\ParserManager\Parser\AbstractProvider; |
24
|
|
|
use SteamMarketProviders\ParserManager\SteamParserFactory; |
25
|
|
|
|
26
|
|
|
class SteamParserTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
public function testWhenProviderMethodCreateUrlNoneReturned(): void |
29
|
|
|
{ |
30
|
|
|
$this->expectExceptionMessage('SteamMarketProviders\ParserManager\Parser\AbstractProvider@anonymous::createUrl(): Return value must be of type SteamMarketProviders\ParserManager\Contract\UrlBuilderInterface, none returned'); |
31
|
|
|
|
32
|
|
|
$provider = new class () extends AbstractProvider { |
33
|
|
|
protected function createUrl(int $page): UrlBuilderInterface |
34
|
|
|
{ |
35
|
|
|
} |
|
|
|
|
36
|
|
|
protected function createParseRules(): ParseRulesBuilder |
37
|
|
|
{ |
38
|
|
|
} |
|
|
|
|
39
|
|
|
}; |
40
|
|
|
|
41
|
|
|
SteamParserFactory::create($provider)->run(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testWhenProviderMethodCreateParseRulesNoneReturned(): void |
45
|
|
|
{ |
46
|
|
|
$this->expectExceptionMessage('SteamMarketProviders\ParserManager\Parser\AbstractProvider@anonymous::createParseRules(): Return value must be of type SteamMarketProviders\ParserManager\Builder\ParseRulesBuilder, none returned'); |
47
|
|
|
|
48
|
|
|
$provider = new class () extends AbstractProvider { |
49
|
|
|
protected function createUrl(int $page): UrlBuilderInterface |
50
|
|
|
{ |
51
|
|
|
return (new SearchUrlBuilder()) |
52
|
|
|
->setAppId(SteamApp::CSGO) |
53
|
|
|
->setPage($page); |
54
|
|
|
} |
55
|
|
|
protected function createParseRules(): ParseRulesBuilder |
56
|
|
|
{ |
57
|
|
|
} |
|
|
|
|
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
SteamParserFactory::create($provider)->run(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: