-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Vantoozz\ProxyScraper\Scrapers; | ||
|
||
/** | ||
* Class ClarketmProxyListScraper | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class ClarketmProxyListScraper extends RemoteTextScraper implements Discoverable | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function remoteTextUrl(): string | ||
{ | ||
return 'https://raw.githubusercontent.com/clarketm/proxy-list/master/proxy-list-raw.txt'; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/integration/Scrapers/ClarketmProxyListScraperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Vantoozz\ProxyScraper\IntegrationTests\Scrapers; | ||
|
||
use Vantoozz\ProxyScraper\IntegrationTests\IntegrationTest; | ||
use Vantoozz\ProxyScraper\Scrapers\ClarketmProxyListScraper; | ||
|
||
/** | ||
* Class ClarketmProxyListScraperTest | ||
* @package Vantoozz\ProxyScraper\IntegrationTests\Scrapers | ||
*/ | ||
final class ClarketmProxyListScraperTest extends IntegrationTest | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_works(): void | ||
{ | ||
$scrapper = new ClarketmProxyListScraper($this->httpClient()); | ||
|
||
$proxies = iterator_to_array($scrapper->get(), false); | ||
|
||
static::assertGreaterThanOrEqual(100, count($proxies)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Vantoozz\ProxyScraper\UnitTests\Scrapers; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vantoozz\ProxyScraper\Enums\Metrics; | ||
use Vantoozz\ProxyScraper\Exceptions\ScraperException; | ||
use Vantoozz\ProxyScraper\Proxy; | ||
use Vantoozz\ProxyScraper\Scrapers\ClarketmProxyListScraper; | ||
use Vantoozz\ProxyScraper\UnitTests\HttpClient\FailingDummyHttpClient; | ||
use Vantoozz\ProxyScraper\UnitTests\HttpClient\PredefinedDummyHttpClient; | ||
|
||
/** | ||
* Class ClarketmProxyListScraperTest | ||
* @package Vantoozz\ProxyScraper\UnitTests\Scrapers | ||
*/ | ||
final class ClarketmProxyListScraperTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_throws_an_exception_on_http_client_error(): void | ||
{ | ||
$this->expectException(ScraperException::class); | ||
$this->expectExceptionMessage('error message'); | ||
|
||
$scraper = new ClarketmProxyListScraper( | ||
new FailingDummyHttpClient('error message') | ||
); | ||
$scraper->get()->current(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_source_metric(): void | ||
{ | ||
$scraper = new ClarketmProxyListScraper( | ||
new PredefinedDummyHttpClient("222.111.222.111:8118\n111.222.111.222:8118") | ||
); | ||
$proxy = $scraper->get()->current(); | ||
|
||
static::assertInstanceOf(Proxy::class, $proxy); | ||
/** @var Proxy $proxy */ | ||
static::assertSame(Metrics::SOURCE, $proxy->getMetrics()[0]->getName()); | ||
static::assertSame(ClarketmProxyListScraper::class, $proxy->getMetrics()[0]->getValue()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_returns_a_proxy(): void | ||
{ | ||
$scraper = new ClarketmProxyListScraper( | ||
new PredefinedDummyHttpClient("222.111.222.111:8118\n111.222.111.222:8118") | ||
); | ||
$proxy = $scraper->get()->current(); | ||
|
||
static::assertInstanceOf(Proxy::class, $proxy); | ||
static::assertSame('222.111.222.111:8118', (string)$proxy); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_skips_bad_rows(): void | ||
{ | ||
$scraper = new ClarketmProxyListScraper( | ||
new PredefinedDummyHttpClient('2312318') | ||
); | ||
|
||
static::assertNull($scraper->get()->current()); | ||
} | ||
} |