Skip to content

Commit

Permalink
+ssl proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Jul 1, 2017
1 parent f6f844c commit 6bca090
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Scrapers/SslProxiesScraper.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 SslProxiesScraper
* @package Vantoozz\ProxyScraper\Scrapers
*/
final class SslProxiesScraper extends AbstractFreeProxyListScraper
{
/**
* @return string
*/
protected function baseUrl(): string
{
return 'https://www.sslproxies.org/';
}
}
24 changes: 24 additions & 0 deletions tests/integration/Scrapers/SslProxiesScraperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types = 1);

namespace Vantoozz\ProxyScraper\IntegrationTests\Scrapers;

use Vantoozz\ProxyScraper\IntegrationTests\IntegrationTest;
use Vantoozz\ProxyScraper\Scrapers\SslProxiesScraper;

/**
* Class SslProxiesScraperTest
* @package Vantoozz\ProxyScraper\Scrapers
*/
final class SslProxiesScraperTest extends IntegrationTest
{
/**
* @test
*/
public function it_works(): void
{
$scrapper = new SslProxiesScraper($this->httpClient());

$proxies = iterator_to_array($scrapper->get());
$this->assertGreaterThanOrEqual(50, count($proxies));
}
}
1 change: 0 additions & 1 deletion tests/system/ProxiesMiner/ScrapersProxiesMiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function addScraper(ScraperInterface $scraper): void
*/
public function getProxies(): array
{

$proxies = [];
foreach ($this->scrapers as $class => $scraper) {
try {
Expand Down
1 change: 1 addition & 0 deletions tests/systemTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Scrapers\ProxyDbScraper::class,
Scrapers\SocksProxyScraper::class,
Scrapers\SpysMeScraper::class,
Scrapers\SslProxiesScraper::class,
Scrapers\UsProxyScraper::class,
] as $class) {
$miner->addScraper($container->get($class));
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/Scrapers/SslProxiesScraperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php declare(strict_types = 1);

namespace Vantoozz\ProxyScraper\UnitTests\Scrapers;

use PHPUnit\Framework\TestCase;
use Vantoozz\ProxyScraper\Exceptions\HttpClientException;
use Vantoozz\ProxyScraper\HttpClient\HttpClientInterface;
use Vantoozz\ProxyScraper\Proxy;
use Vantoozz\ProxyScraper\Scrapers\SslProxiesScraper;

final class SslProxiesScraperTest extends TestCase
{
/**
* @test
* @expectedException \Vantoozz\ProxyScraper\Exceptions\ScraperException
* @expectedExceptionMessage error message
*/
public function it_throws_an_exception_on_http_client_error(): void
{
/** @var HttpClientInterface|\PHPUnit_Framework_MockObject_MockObject $httpClient */
$httpClient = $this->createMock(HttpClientInterface::class);
$httpClient
->expects(static::once())
->method('get')
->willThrowException(new HttpClientException('error message'));

$scraper = new SslProxiesScraper($httpClient);
$scraper->get()->current();
}

/**
* @test
*/
public function it_returns_a_proxy(): void
{
/** @var HttpClientInterface|\PHPUnit_Framework_MockObject_MockObject $httpClient */
$httpClient = $this->createMock(HttpClientInterface::class);
$httpClient
->expects(static::once())
->method('get')
->willReturn('<table id="proxylisttable"><tbody><tr><td>46.101.55.200</td><td>8118</td></tr></table>');

$scraper = new SslProxiesScraper($httpClient);
$proxy = $scraper->get()->current();

$this->assertInstanceOf(Proxy::class, $proxy);
$this->assertSame('46.101.55.200:8118', (string)$proxy);
}

/**
* @test
*/
public function it_skips_bad_rows(): void
{
/** @var HttpClientInterface|\PHPUnit_Framework_MockObject_MockObject $httpClient */
$httpClient = $this->createMock(HttpClientInterface::class);
$httpClient
->expects(static::once())
->method('get')
->willReturn('<table id="proxylisttable"><tbody><tr><td>111</td><td>111</td></tr></table>');

$scraper = new SslProxiesScraper($httpClient);

$this->assertNull($scraper->get()->current());
}
}

0 comments on commit 6bca090

Please sign in to comment.