Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New relic client for deployment notification
- Loading branch information
Showing
2 changed files
with
87 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,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 | ||
); | ||
} | ||
} |
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,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(); | ||
} | ||
} |