Skip to content

Commit

Permalink
+foxtools
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Jun 30, 2017
1 parent 3bfafdf commit e5f859a
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Scrapers/FoxToolsScraper.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 FoxToolsScraper
* @package Vantoozz\ProxyScraper\Scrapers
*/
final class FoxToolsScraper extends RemoteTextScraper
{
/**
* @return string
*/
protected function remoteTextUrl(): string
{
return 'http://api.foxtools.ru/v2/Proxy.txt';
}
}
25 changes: 25 additions & 0 deletions tests/integration/Scrapers/FoxToolsScraperTest.php
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));
}
}
70 changes: 70 additions & 0 deletions tests/unit/Scrapers/FoxToolsScraperTest.php
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());
}
}

0 comments on commit e5f859a

Please sign in to comment.