Skip to content

Commit

Permalink
+ proxy metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Sep 21, 2017
1 parent 15ec84c commit 78fbbff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ final class Proxy
*/
private $port;

/**
* @var array
*/
private $metrics = [];

/**
* Proxy constructor.
* @param Ipv4 $ipv4
Expand All @@ -29,6 +34,22 @@ public function __construct(Ipv4 $ipv4, Port $port)
$this->port = $port;
}

/**
* @param Metric $metric
*/
public function addMetric(Metric $metric): void
{
$this->metrics[] = $metric;
}

/**
* @return Metric[]
*/
public function getMetrics(): array
{
return $this->metrics;
}

/**
* @return string
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Vantoozz\ProxyScraper\Ipv4;
use Vantoozz\ProxyScraper\Metric;
use Vantoozz\ProxyScraper\Port;
use Vantoozz\ProxyScraper\Proxy;

Expand Down Expand Up @@ -41,4 +42,20 @@ public function it_returns_port(): void
$proxy = new Proxy(new Ipv4('192.168.0.1'), $port);
$this->assertSame($port, $proxy->getPort());
}

/**
* @test
*/
public function it_stores_metrics(): void
{
$one = new Metric('one', 111);
$two = new Metric('two', 222);

$proxy = new Proxy(new Ipv4('8.8.8.8'), new Port(8888));

$proxy->addMetric($one);
$proxy->addMetric($two);

$this->assertSame([$one, $two], $proxy->getMetrics());
}
}

0 comments on commit 78fbbff

Please sign in to comment.