Skip to content

Commit

Permalink
+ ClarketmProxyListScraper
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Jun 2, 2020
1 parent af939ad commit c12e234
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Scrapers/ClarketmProxyListScraper.php
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 tests/integration/Scrapers/ClarketmProxyListScraperTest.php
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));
}
}
74 changes: 74 additions & 0 deletions tests/unit/Scrapers/ClarketmProxyListScraperTest.php
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());
}
}

0 comments on commit c12e234

Please sign in to comment.