Skip to content

Commit

Permalink
New relic client for deployment notification
Browse files Browse the repository at this point in the history
  • Loading branch information
mkpeacock committed May 27, 2016
1 parent d4dabee commit 3f009b7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Clients/NewRelicClient.php
@@ -0,0 +1,29 @@
<?php

namespace ParityBit\DeploymentNotifier\Clients;

use Curl\Curl;

class NewRelicClient
{
protected $curl;
protected $appName;

const NOTIFICATION_URL = 'https://api.newrelic.com/deployments.xml';

public function __construct(Curl $curl, $apiKey, $appName)
{
$this->curl = $curl;
$this->curl->setHeader('x-api-key', $apiKey);
$this->appName = $appName;
}

public function logDeployment()
{
// SHOULDDO: Use API v2
$this->curl->post(
self::NOTIFICATION_URL,
'deployment[app_name]=' . $this->appName
);
}
}
58 changes: 58 additions & 0 deletions tests/Clients/NewRelicClientTest.php
@@ -0,0 +1,58 @@
<?php

namespace ParityBit\DeploymentNotifier\Clients;

use Curl\Curl;

class NewRelicClientTest extends \PHPUnit_Framework_TestCase
{
protected $client;
protected $apiKey;
protected $appName;
protected $faker;

public function setUp()
{
$this->faker = \Faker\Factory::create();

$this->curl = $this->getMockBuilder(Curl::class)
->setMethods(['post', 'setHeader'])
->getMock();

$this->apiKey = $this->faker->uuid;
$this->appName = $this->faker->name;

$this->buildClient();
}

protected function buildClient()
{
$this->client = new NewRelicClient(
$this->curl,
$this->apiKey,
$this->appName
);
}

public function testConstructorSetsApiKeyHeader()
{
$this->curl->expects($this->once())->method('setHeader')->with($this->equalTo('x-api-key'), $this->equalTo($this->apiKey));
$this->buildClient();
}

/**
* @depends testConstructorSetsApiKeyHeader
*/
public function testLogDeployment()
{
$this->curl->expects($this->once())
->method('post')
->with(
$this->equalTo(NewRelicClient::NOTIFICATION_URL),
$this->equalTo('deployment[app_name]=' . $this->appName)
);

$this->buildClient();
$this->client->logDeployment();
}
}

0 comments on commit 3f009b7

Please sign in to comment.