-
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
5 changed files
with
109 additions
and
1 deletion.
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 SslProxiesScraper | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class SslProxiesScraper extends AbstractFreeProxyListScraper | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function baseUrl(): string | ||
{ | ||
return 'https://www.sslproxies.org/'; | ||
} | ||
} |
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,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)); | ||
} | ||
} |
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
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
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,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()); | ||
} | ||
} |