コード例 #1
0
 public function testReport()
 {
     // Empty report
     $this->assertEmpty($this->report->gate);
     $this->assertEmpty($this->report->door);
     $this->assertFalse($this->report->containsError());
     $this->assertSame(0, count($this->report->actions));
     // Adds a first action
     // Our report should be valid.
     $action = new AMQPAction('method', 'target');
     $this->report->addAction($action);
     $this->assertSame(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->assertSame(2, count($this->report->actions));
     $this->assertTrue($this->report->containsError());
     // Attaches to gate
     $this->report->attachToGate('QuuxGate', 'Quuxians');
     $this->assertSame('QuuxGate', $this->report->gate);
     $this->assertSame('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.');
 }
コード例 #2
0
 /**
  * Prepares a report and fires a report event
  */
 protected function report()
 {
     $actionToReport = new AMQPAction("publish", $this->target, $this->routingKey);
     if ($this->exception !== null) {
         $actionToReport->attachError(new ActionError($this->exception));
     }
     Event::fire(new ReportEvent($actionToReport));
 }