Page MenuHomeDevCentral

No OneTemporary

diff --git a/tests/Http/PayloadFullTest.php b/tests/Http/PayloadFullTest.php
index 5e129e0..d60119b 100644
--- a/tests/Http/PayloadFullTest.php
+++ b/tests/Http/PayloadFullTest.php
@@ -1,54 +1,77 @@
<?php
namespace Nasqueron\Notifications\Tests;
use Storage;
class PayloadFullTest extends TestCase {
public function setUp () {
parent::setUp();
$this->disableBroker();
}
/**
* Tests a GitHub gate payload.
*/
public function testPost () {
$payload = file_get_contents(__DIR__ . '/../data/GitHubPingPayload.json');
$this->sendPayload(
'/gate/GitHub/Acme', // A gate existing in data/credentials.json
$payload,
'POST',
[
'X-Github-Event' => 'ping',
'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
'X-Hub-Signature' => 'sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc',
]
)->seeJson([
'gate' => 'GitHub',
'door' => 'Acme',
'action' => 'AMQPAction'
]);
$this->assertResponseOk();
}
/**
* Tests a GitHub gate payload.
*/
public function testInvalidSignature () {
$payload = file_get_contents(__DIR__ . '/../data/GitHubPingPayload.json');
$this->sendPayload(
'/gate/GitHub/Acme', // A gate existing in data/credentials.json
$payload,
'POST',
[
'X-Github-Event' => 'ping',
'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
'X-Hub-Signature' => 'sha1=somethingwrong',
]
);
$this->assertResponseStatus(403);
}
+
+ public function testBrokerIssue () {
+ $this->mockNotOperationalBroker();
+
+ $payload = file_get_contents(__DIR__ . '/../data/GitHubPingPayload.json');
+ $this->sendPayload(
+ '/gate/GitHub/Acme', // A gate existing in data/credentials.json
+ $payload,
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c',
+ 'X-Hub-Signature' => 'sha1=25f6cbd17ea4c6c69958b95fb88c879de4b66dcc',
+ ]
+ )->seeJson([
+ 'gate' => 'GitHub',
+ 'door' => 'Acme',
+ 'action' => 'AMQPAction',
+ 'type' => 'RuntimeException',
+ ]);
+
+ $this->assertResponseStatus(503);
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index d4e12c4..9a0974c 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -1,102 +1,115 @@
<?php
namespace Nasqueron\Notifications\Tests;
use Illuminate\Contracts\Console\Kernel;
use Keruald\Broker\BlackholeBroker;
+use Keruald\Broker\Broker;
use Mockery;
class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
///
/// Helpers to mock application services
///
/**
* Mocks the events dispatcher
*/
public function disableEvents () {
// Disables events
// This allows to test a single component and not all the application
$mock = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
$mock->shouldReceive('fire');
$mock->shouldReceive('listen');
$this->app->instance('events', $mock);
}
/**
* Mocks the broker
*/
public function disableBroker () {
$broker = new BlackholeBroker();
$broker->acceptAllMethodCalls(); // allows to be used as a mock
$this->app->instance('broker', $broker);
}
+ /**
+ * Mocks the broker, throwing an exception when sendMessage is called.
+ */
+ public function mockNotOperationalBroker () {
+ $mock = Mockery::mock('Keruald\Broker\Broker');
+ $mock->shouldReceive('connect');
+ $mock->shouldReceive('setExchangeTarget->routeTo->sendMessage')
+ ->andThrow(new \RuntimeException);
+
+ $this->app->instance('broker', $mock);
+ }
+
///
/// Helpers to post data to gates
///
/**
* Visits the given URI with a JSON request.
*
* @param string $uri
* @param mixed $data
* @param string $method
* @param array $headers
* @return $this
*/
public function sendJsonPayload ($uri, $data, $method = 'POST', array $headers = []) {
$content = json_encode($data);
$headers = array_merge([
'CONTENT_TYPE' => 'application/json',
'Accept' => 'application/json',
], $headers);
return $this->sendPayload($uri, $content, $method, $headers);
}
/**
* Visits the given URI with a raw request.
*
* @param string $uri
* @param string $content
* @param string $method
* @param array $headers
* @return $this
*/
public function sendPayload ($uri, $content, $method = 'POST', array $headers = []) {
$headers = array_merge([
'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
], $headers);
$this->call(
$method, $uri, [], [], [], $this->transformHeadersToServerVars($headers), $content
);
return $this;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Oct 12, 10:28 (1 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065749
Default Alt Text
(5 KB)

Event Timeline