-
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
113 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 FoxToolsScraper | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class FoxToolsScraper extends RemoteTextScraper | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
protected function remoteTextUrl(): string | ||
{ | ||
return 'http://api.foxtools.ru/v2/Proxy.txt'; | ||
} | ||
} |
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,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Vantoozz\ProxyScraper\IntegrationTests\Scrapers; | ||
|
||
use Vantoozz\ProxyScraper\IntegrationTests\IntegrationTest; | ||
use Vantoozz\ProxyScraper\Scrapers\FoxToolsScraper; | ||
|
||
/** | ||
* Class FoxToolsScraperTest | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class FoxToolsScraperTest extends IntegrationTest | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function it_works(): void | ||
{ | ||
$scrapper = new FoxToolsScraper($this->httpClient()); | ||
|
||
$proxies = iterator_to_array($scrapper->get()); | ||
|
||
$this->assertGreaterThanOrEqual(80, 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,70 @@ | ||
<?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\FoxToolsScraper; | ||
|
||
/** | ||
* Class FoxToolsScraperTest | ||
* @package Vantoozz\ProxyScraper\Scrapers | ||
*/ | ||
final class FoxToolsScraperTest 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 FoxToolsScraper($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("222.111.222.111:8118\n111.222.111.222:8118"); | ||
|
||
$scraper = new FoxToolsScraper($httpClient); | ||
$proxy = $scraper->get()->current(); | ||
|
||
$this->assertInstanceOf(Proxy::class, $proxy); | ||
$this->assertSame('222.111.222.111: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('2312318'); | ||
|
||
$scraper = new FoxToolsScraper($httpClient); | ||
|
||
$this->assertNull($scraper->get()->current()); | ||
} | ||
} |