Page MenuHomeDevCentral

D176.diff
No OneTemporary

D176.diff

diff --git a/tests/Actions/ActionsReportTest.php b/tests/Actions/ActionsReportTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Actions/ActionsReportTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Actions;
+
+use Illuminate\Foundation\Testing\WithoutMiddleware;
+
+use Nasqueron\Notifications\Actions\ActionError;
+use Nasqueron\Notifications\Actions\ActionsReport;
+use Nasqueron\Notifications\Actions\AMQPAction;
+use Nasqueron\Notifications\Tests\TestCase;
+
+class ActionsReportTest extends TestCase {
+
+ protected $report;
+
+ public function setUp () {
+ $this->report = new ActionsReport();
+ }
+
+ public function testReport () {
+ // Empty report
+ $this->assertEmpty($this->report->gate);
+ $this->assertEmpty($this->report->door);
+ $this->assertFalse($this->report->containsError());
+ $this->assertEquals(0, count($this->report->actions));
+
+ // Adds a first action
+ // Our report should be valid.
+ $action = new AMQPAction(
+ 'method',
+ 'target'
+ );
+ $this->report->addAction($action);
+
+ $this->assertEquals(1, count($this->report->actions));
+ $this->assertFalse($this->report->containsError());
+
+ // Let's attach an exception to a new action.
+ // Our report should then be invalid.
+ $action = new AMQPAction(
+ 'methodWithException',
+ 'target'
+ );
+ $ex = new \RuntimeException('Lorem ipsum dolor');
+ $action->attachError(new ActionError($ex));
+ $this->report->addAction($action);
+
+ $this->assertEquals(2, count($this->report->actions));
+ $this->assertTrue($this->report->containsError());
+
+ // Attaches to gate
+ $this->report->attachToGate('QuuxGate', 'Quuxians');
+ $this->assertEquals('QuuxGate', $this->report->gate);
+ $this->assertEquals('Quuxians', $this->report->door);
+
+ // Test rendering
+ $actualReport = (string)$this->report;
+ $expectedReport = file_get_contents(__DIR__ . '/../data/report.json');
+
+ $score = similar_text($expectedReport, $actualReport);
+ $this->assertGreaterThan(550, $score, 'data/report.json and rendered report differ too much. Try $this->assertEquals($expectedReport, $actualReport) to see a diff.');
+ }
+}
diff --git a/tests/data/report.json b/tests/data/report.json
new file mode 100644
--- /dev/null
+++ b/tests/data/report.json
@@ -0,0 +1,24 @@
+{
+ "actions": [
+ {
+ "method": "method",
+ "target": "target",
+ "routingKey": "",
+ "action": "AMQPAction",
+ "error": null
+ },
+ {
+ "method": "methodWithException",
+ "target": "target",
+ "routingKey": "",
+ "action": "AMQPAction",
+ "error": {
+ "type": "RuntimeException",
+ "message": "Lorem ipsum dolor"
+ }
+ }
+ ],
+ "created": 1452266121,
+ "gate": "QuuxGate",
+ "door": "Quuxians"
+}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 02:40 (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307256
Default Alt Text
D176.diff (3 KB)

Event Timeline