Page MenuHomeDevCentral

D195.diff
No OneTemporary

D195.diff

diff --git a/app/Providers/ReportServiceProvider.php b/app/Providers/ReportServiceProvider.php
--- a/app/Providers/ReportServiceProvider.php
+++ b/app/Providers/ReportServiceProvider.php
@@ -2,7 +2,7 @@
namespace Nasqueron\Notifications\Providers;
-use Illuminate\Events\Dispatcher;
+use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Nasqueron\Notifications\Actions\ActionsReport;
@@ -26,7 +26,7 @@
* Listen to actions fired by the application to add to the report
*
* @param Nasqueron\Notifications\Actions\ActionsReport $report The report to add actions to
- * @param Illuminate\Events\Dispatcher $events The application events
+ * @param Illuminate\Contracts\Events\Dispatcher $events The application events dispatcher
*/
public static function listenToActionsForReport (ActionsReport $report, Dispatcher $events) {
$events->listen(
diff --git a/tests/Http/Controllers/GitHubGateControllerTest.php b/tests/Http/Controllers/GitHubGateControllerTest.php
--- a/tests/Http/Controllers/GitHubGateControllerTest.php
+++ b/tests/Http/Controllers/GitHubGateControllerTest.php
@@ -2,11 +2,15 @@
namespace Nasqueron\Notifications\Tests\Http\Controllers;
-use Illuminate\Foundation\Testing\WithoutMiddleware;
-
use Nasqueron\Notifications\Tests\TestCase;
class GitHubGateControllerTest extends TestCase {
+ public function setUp () {
+ parent::setUp();
+
+ $this->disableEvents();
+ }
+
/**
* GitHub gate works.
*
@@ -16,4 +20,27 @@
$this->visit('/gate/GitHub')
->see('POST');
}
+
+ /**
+ * Tests a GitHub gate payload.
+ */
+ public function testPost () {
+ $payload = file_get_contents(__DIR__ . '/../../data/GitHubPingPayload.json');
+ $this->sendPayload(
+ '/gate/GitHub/Quux',
+ $payload,
+ 'POST',
+ [
+ 'X-Github-Event' => 'ping',
+ 'X-Github-Delivery' => 'e5dd9fc7-17ac-11e5-9427-73dad6b9b17c'
+ ]
+ )
+ ->seeJson([
+ 'gate' => 'GitHub',
+ 'door' => 'Quux',
+ 'actions' => []
+ ]);
+
+ $this->assertResponseOk();
+ }
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -4,6 +4,8 @@
use Illuminate\Contracts\Console\Kernel;
+use Mockery;
+
class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
/**
@@ -26,4 +28,65 @@
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);
+ }
+
+ ///
+ /// 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;
+ }
}
diff --git a/tests/data/GitHubPingPayload.json b/tests/data/GitHubPingPayload.json
new file mode 100644
--- /dev/null
+++ b/tests/data/GitHubPingPayload.json
@@ -0,0 +1 @@
+{"zen":"Practicality beats purity.","hook_id":6474950,"hook":{"url":"https://api.github.com/orgs/nasqueron/hooks/6474950","ping_url":"https://api.github.com/orgs/nasqueron/hooks/6474950/pings","id":6474950,"name":"web","active":true,"events":["*"],"config":{"url":"https://notifications-dereckson.c9users.io/gate/GitHub","content_type":"json","insecure_ssl":"0","secret":"********"},"updated_at":"2015-11-22T06:25:12Z","created_at":"2015-11-22T06:25:12Z"},"organization":{"login":"nasqueron","id":5605546,"url":"https://api.github.com/orgs/nasqueron","repos_url":"https://api.github.com/orgs/nasqueron/repos","events_url":"https://api.github.com/orgs/nasqueron/events","members_url":"https://api.github.com/orgs/nasqueron/members{/member}","public_members_url":"https://api.github.com/orgs/nasqueron/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/5605546?v=3","description":"Central hub of a budding community of creative people, writers, developers and thinkers."},"sender":{"login":"dereckson","id":135563,"avatar_url":"https://avatars.githubusercontent.com/u/135563?v=3","gravatar_id":"","url":"https://api.github.com/users/dereckson","html_url":"https://github.com/dereckson","followers_url":"https://api.github.com/users/dereckson/followers","following_url":"https://api.github.com/users/dereckson/following{/other_user}","gists_url":"https://api.github.com/users/dereckson/gists{/gist_id}","starred_url":"https://api.github.com/users/dereckson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dereckson/subscriptions","organizations_url":"https://api.github.com/users/dereckson/orgs","repos_url":"https://api.github.com/users/dereckson/repos","events_url":"https://api.github.com/users/dereckson/events{/privacy}","received_events_url":"https://api.github.com/users/dereckson/received_events","type":"User","site_admin":false}}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 07:22 (16 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259712
Default Alt Text
D195.diff (6 KB)

Event Timeline